Hi,
I have a question regarding formats
I have numeric variable AGE and I want to give ranges while I write formats
age is integer here
proc format;
value afefmt /*WHEN DO I NEED TO PUT A DOLLAR SIGN HERE......SINCE THE VARIABLE WE HAVE IS NUMERIC .THERE IS NO $ SIGN???????
0-<20= "0-19"
Thanks
You only need a $ format if the use will be for character formats. If your ages were character you would use
value $agefmt ..
though you'd likely get unexpected results.
Yes i understand. Is the unexpected results because of the Range upper limits and lower limits?
Unless we specify with TILde ???
Regards
Unexpected results come from the sort of character variables: "9" is > "10" as the comparison generally starts with the first characters. So ranges like "1" - "20" are valid in proc format but values of "3", "4", "5" are not between "1" and "20" .
See what happens with this code:
data temp;
length x $ 2;
input x $;
datalines;
1
20
3
4
5
6
7
11
;
run;
proc sort; by x;run;
proc print;run;
Not sure what your exact question is. If I am following it then here is the response:
Proc format can be used to format numeric variables and assign them a range. The advantage of that is you can presentt the data using proc report or proc freq as a range; whereas for analysis of numeric data like proc means it will treat this as a continuous variable.
Test the code below using examples of proc freq and proc means. In the freq procedure the output will be range. In the means procedure the age will be rightly handled as a numeric variable.
data test;
input age;
datalines;
1
21
3
5
6
88
99
;
run;
proc format;
value age 1-19='0-19'
20-99='>20'
;
quit;
proc freq data=test;
tables age;
format age age.;
run;
proc means data=test;
var age;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.