Hi Team,
I have a format written like shown below:
VALUE SURGERIES
0-3 ="0-3"
4-6="4-6"
7-9="7-9"
10-12="10-12"
13-15="13-15"
16-20="16-20"
21-high="21-high"
other=" "
;
Unfortunately after I applied it on a variable , final dataset has the order like the shown below!!!!!!!!! I wanted in the order shown above
0-3
10-12
13-15
16-20
21-high
4-6
7-9
In any format the part on the right side of the equals sign is the displayed value, it doesn't matter if the format is numeric, character or a picture format.
Unfortunately after I applied it on a variable , final dataset has the order like the shown below!!!!!!!!! I wanted in the order shown above
0-3
10-12
13-15
16-20
21-high
4-6
7-9
Formats do not change the order of a dataset.
Please explain further what you mean.
I wrote the above format for a variable in my dataset. The variable is numeric. After I applied the format and the variable went into a macro for the proc freq and the macro has several other variables too on which different formats were applied and on which proc freq was done as well.
The final dataset(ready to go for a report) has the unexpected order listed
Thanks
I unless you sort on the formatted value the order doesn't change. For output with the format applied such as in proc freq the order will use the collating sequence in effect. If you want the order of the formatted output in a better order then you need to pay attention to that sequence when designing formats.
Notice the FIRST character in each of your formats is in sequence.
You use you want to have a leading blank or blanks to sort correctly like: " 0-3", " 4-6" and " 7-9" .
If you have larger value range you may need multiple blanks such as " 0 - 9999" and "10000+"
Hi ,
As far as I understand u want me to write a char format for that numeric variable and insert leading blanks where ever necessary???
Thanks
After I applied the format and the variable went into a macro for the proc freq
Based on this information, we have a better chance of providing good advice. PROC FREQ was not mentioned in the original question, so it was unlikely that the problem could properly be answered based on your original question. I would advise at this point for you to provide more details about your problem, as it seems your initial posts leave out important details.
u want me to write a char format for that numeric variable
No, I think ballardw is saying create a numeric format for that variable, but do it differently than you are doing it, as he suggests. (You can't create a character format for a numeric variable)
I was thinking leading space works only for char formats
In any format the part on the right side of the equals sign is the displayed value, it doesn't matter if the format is numeric, character or a picture format.
THANK YOUUUUUUUUUUUUUUUUU;
Unless u put this sentence (I didnt know why)....but I was changing the stuff on the left side
Now after reading your sentence i put spaces on the right side AND IT WORKS FOR ME
VALUE SURGERIES
0-3 =" 0-3" -------added space infront of 0 after equal sign
4-6=" 4-6" -------added space infront of 4 after equal sign
7-9=" 7-9" -------added space infront of 7 after equal sign
10-12="10-12"
13-15="13-15"
16-20="16-20"
21-high="21+"
other=" "
;
Sorry for the Delayed response
Thanks a tonn
Karun,
If you are creating a new variable based on the format you created, you can always sort the file changing the collation order used. For example, does the following do what you want?:
proc format;
VALUE SURGERIES
0-3 ="0-3"
4-6="4-6"
7-9="7-9"
10-12="10-12"
13-15="13-15"
16-20="16-20"
21-high="21-high"
other=" ";
run;
data class;
set sashelp.class;
age=ifn(_n_ lt 19,_n_,22);
agegroup=put(age,surgeries.);
run;
proc sort data=class SORTSEQ=LINGUISTIC(NUMERIC_COLLATION=ON);
by agegroup;
run;
Hi,
Your example works fine. But I couldnt figure out exactly myself on how to overcome the current situation.
what is this step doing????
age=ifn(_n_ lt 19,_n_,22);
I have several variables created based on the formats i created///
Karun,
I only used that function to change the values of age so that they would match all of your categories in order to have a file to test with your format. The statement just makes the first 18 records of sashelp.class to have ages of 1 to 18, and assigns a value of 22 to the 19th record.
The real question, as others have already asked, is what are you really trying to accomplish?
Great Help
Regards
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.