Programming the statistical procedures from SAS

Formats-error

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,040
Accepted Solution

Formats-error


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


Accepted Solutions
Solution
‎10-18-2012 11:46 AM
Super User
Posts: 10,867

Re: Formats-error

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


All Replies
Trusted Advisor
Posts: 1,671

Re: Formats-error

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.

Super Contributor
Posts: 1,040

Re: Formats-error


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

Super User
Posts: 10,867

Re: Formats-error

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

Super Contributor
Posts: 1,040

Re: Formats-error

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

Trusted Advisor
Posts: 1,671

Re: Formats-error

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)

Super Contributor
Posts: 1,040

Re: Formats-error

I was thinking leading space works only for char formats

Solution
‎10-18-2012 11:46 AM
Super User
Posts: 10,867

Re: Formats-error

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.

Super Contributor
Posts: 1,040

Re: Formats-error

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

PROC Star
Posts: 7,416

Re: Formats-error

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;

Super Contributor
Posts: 1,040

Re: Formats-error

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

PROC Star
Posts: 7,416

Re: Formats-error

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?

Super Contributor
Posts: 1,040

Re: Formats-error

Great Help

Regards

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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