proc format; value scorefmt low-539 ="SCORE<540" 540-559="540<=SCORE<560" 560-579="560<=SCORE<580"; run; data Range; length SCORE_LBL $15. Sort_order 8.; SCORE_LBL="SCORE<540"; Sort_order=1;output; SCORE_LBL="540<=SCORE<560"; Sort_order=2;output; SCORE_LBL="560<=SCORE<580"; Sort_order=3;output; SCORE_LBL="580<=SCORE<600"; Sort_order=4;output; SCORE_LBL="600<=SCORE<620"; Sort_order=5;output; ; run; proc print data=Range; run;
I have some proc format code. my question is, is the programs creating the variable SCORE_LBL and Sort_order from nothing? there is no input data set and dataset Range is created. so What is happening in the proc format code? where does score_lbl or is it an assumption for later use if we feed in scores...?
Since the FORMAT is not used anywhere in the Data step it has absolutely nothing to do with the contents of the data set Range.
You would have to see Scorefmt. used somewhere for the format to be used. Either in a FORMAT, ATTRIB or PUT statement most likely.
The data step is a way to create data that contains the character values desired for a variable named Score_lbl and a numeric variable named order. The OUTPUT writes each set of values to the data set Range.
The Proc Format Step creates a SAS format with the name scorefmt. The format is used to display variable values translated to (in this case) one of 3 categories, so any value lower than 540 is displayed as "SCORE<540".
The Data Step is not using the created format. It creates a data set with 5 rows, each containing a text variable with a category text similar to the category text used in the format, but here 5 categories instead of the 3 in the format. The table is then printed, but apart from that in can't be used to anything, so it makes no sense. The categories must be implemented as a format to be of any use.
To answer you detailed question, yes the RANGE dataset is being made just from that data step. The OUTPUT statements are what is writing the observations to the dataset.
You should look further down in the program to see what the RANGE dataset is going to be used for.
We can make a guess. It looks like it is assigning a numeric value for each of the series of text strings. So most likely it will be used to make sure those text strings can be sorted into the right order in some future report somewhere.
Note there is no need to add periods to the lengths specified in the LENGTH statement. SAS variables can only have integer lengths.
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!
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.