SAS Blog 3: Formats and Labels

Welcome to the 3rd set of blog  The topic under discussion is formats and labels.

The SAS gives us an advantage to create user defined formats and manipulate the display as per our requirements. Here also we are taking an example of a question and we will look into the scenario where we would be creating our own user defined formats .

Q1) Create the below mentioned dataset voter:


Code:
/*Part1*/

proc format;
value age 0-30 = 'Between 0 and 31'
31-50 = 'between 31 and 50'
51-70 = 'between 51 and 70'
71-High = 'greater than 71';
value $party
N = 'National Democratic alliance'
U = 'United Progressive Alliance'
;
value $hello
1 = 'strongly disagree'
2 = 'disagree'
3 = 'no opinion'
4 = 'agree'
5 = 'strongly agree'
;
/*part2*/
data voter;
input Age Party : $1.(Ques1-Ques4)($1.+1);
format Age age. party $party. Ques1-Ques4 $hello.;
label Ques1 = 'prime minister is doing a good job'
Ques 2 = 'parliament is doing a good job'
Ques 3 = 'taxes are too high'
Ques 4 = 'Government hould cut spending';
datalines;
23 N 1 1 2 2
45 U 5 5 4 1
67 N 2 4 3 3
39 U 4 4 4 4
19 N 2 1 2 1
75 N 3 3 2 3
57 U 4 3 4 4
;
proc print data=voter;
run;
proc contents data=voter varnum;
run;
 proc freq data=voter;
tables Ques1-Ques4;
run;

Cumulative Explanation:

Part 1:
This is the syntax for procedure format to help you create user defined format.In this example we have created the format age with different range , party and hello. The syntax is specifying the format name along with the keyword value. Do specify $in case of character format type.
 
Part 2:
 
We are creating a dataset voter and calling the format types using the keyword format. Do remember to end the format type with the period .Eg: format age age.
 
Output:
Proc Print
 
 
 
Contents
 
 
 
Frequency
 
Extra Inputs:
 
1)  We can create permanent format sets:
 
Code Eg for the above one:
 
libname praxis 'C:\Users\Elcot\Desktop\Sharath SAS\neha sas cody book';
proc  format library=praxis;
value age 0-30 = 'Between 0 and 31'
31-50 = 'between 31 and 50'
51-70 = 'between 51 and 70'
71-High = 'greater than 71';
value $party
N = 'National Democratic alliance'
U = 'United Progressive Alliance'
;
value $hello
1 = 'strongly disagree'
2 = 'disagree'
3 = 'no opinion'
4 = 'agree'
5 = 'strongly agree'
;
 
Here we are giving the permanent library reference
 
 2) Suppose you end the  programme and you want to use format you once created
Please do mention the following statement:
 
options fmtsearch = (library name);
 
 
Please follow blog 1 and blog 2 for working the simple data sets.
 
 
 
 
 
 
 
 
 
 
 




 

Comments

Popular posts from this blog

Kabaddi Match: Lets meet at the arena!! Aa jao Dam Dikhane!!!

Text Analytics Using R - Part A: Extraction of reviews of galaxy s4 product reviews in flipkart

Replace your Social Media with the New Age Social Media: Fitness with Motivation