BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8


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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

12 REPLIES 12
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
robertrao
Quartz | Level 8


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

ballardw
Super User

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+"

robertrao
Quartz | Level 8

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

PaigeMiller
Diamond | Level 26

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)

--
Paige Miller
robertrao
Quartz | Level 8

I was thinking leading space works only for char formats

ballardw
Super User

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.

robertrao
Quartz | Level 8

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

art297
Opal | Level 21

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;

robertrao
Quartz | Level 8

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///

art297
Opal | Level 21

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?

robertrao
Quartz | Level 8

Great Help

Regards

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 ANOVA?

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.

Discussion stats
  • 12 replies
  • 1915 views
  • 7 likes
  • 4 in conversation