BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8
data range;
length score_lbl $15. sort_order 8.;
score_lbl="score<540"; sort_order=1; output;
score_lbl="540<=score<550"; sort_order=2; output;
score_lbl="550<score<560"; sort+order=3;output;
run;



how does this work? assign value to score_lbl and sort_order in turn and output together?

 

6 REPLIES 6
Kurt_Bremser
Super User

Maxim 1: Read the Documentation.

OUTPUT Statement 

Your head will not explode, and you won't lose your eyesight or suffer similar mishaps. Once you've done that, and there are parts of the doc which are unclear to you, come back here, and we'll clear them up.

PaigeMiller
Diamond | Level 26

@HeatherNewton wrote:
data range;
length score_lbl $15. sort_order 8.;
score_lbl="score<540"; sort_order=1; output;
score_lbl="540<=score<550"; sort_order=2; output;
score_lbl="550<score<560"; sort+order=3;output;
run;



how does this work? assign value to score_lbl and sort_order in turn and output together?

 


It doesn't work, because you have no SET statement or INPUT statement. All values are missing.

 

Of course, if we take a step back, the text string of SCORE_LBL has to be sorted to get them into order, because SAS by default sort text alphabetically, not numerically. It would be far better if SCORE were kept as a numeric value and not converted into a text variable, and then the values of score will sort numerically. How to use SCORE as a numeric variable? Assign custom formats, rather the creating a new text variable.

 

proc format;
    value scoref low-<540='Score < 540' 
        540-<550='540<=Score<550'
        550-<560='550<=Score<560';
run;

/* Example of use */
proc freq data=have order=internal;
    table score;
    format score scoref.;
run;

So don't assign ranges as text strings; assign ranges as a custom format.

--
Paige Miller
HeatherNewton
Quartz | Level 8
proc format;
value SCOREFMT
low-539="SCORE<540"
540-559="540<=SCORE<560"
;
RUN;

DATA RANGE;
LENGTH SCORE_LBL $25. SORT_ORDER 8.;
SCORE_LBL="SCORE<540"; SORT_ORDER=1; OUTPUT;
SCORE_LBL="540<=SCORE<560"; SORT_ORDER=2; OUTPUT;
RUN;

PROC PRINT DATA=RANGE;
RUN;

actually this is the code. 

when print, I get score_lbl instead of score as variable name, 

it shows score_lbl and sort_order not score

how does this work?

PaigeMiller
Diamond | Level 26
proc format;
    value scoref low-<540='Score < 540' 
        540-<550='540<=Score<550'
        550-<560='550<=Score<560';
run;

/* Example of use */
proc print data=range(drop=score_lbl);
    format score scoref.;
run;
--
Paige Miller
Tom
Super User Tom
Super User

It is just creating a dataset with three observations and two variables.

So it is just an overly complicated way of writing this data step.

data range;
  sort_order +1 ;
  input score_lbl $15. ;
cards;
score<540
540<=score<550
550<score<560
;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 6 replies
  • 444 views
  • 3 likes
  • 4 in conversation