BookmarkSubscribeRSS Feed
robertrao
Quartz | Level 8

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

4 REPLIES 4
ballardw
Super User

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.

robertrao
Quartz | Level 8

Yes i understand. Is the unexpected results because of the Range upper limits and lower limits?

Unless we specify with TILde ???

Regards

ballardw
Super User

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;

pronabesh
Fluorite | Level 6

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 859 views
  • 0 likes
  • 3 in conversation