I read the doc but dont understand as the example is not complete. I try the code attached,
data pf_lemon; input scorefmt $; datalines; low-539 540-559 560-579 run; proc format data=pf_lemon; value scorefmt low-539 ="apple" 540-559="540<=SCORE<560" 560-579="560<=SCORE<580"; run; proc print data=pf_lemon; run;
how can I make it work?
Three problems:
proc format;
value $scorefmt
'low-539' ="apple"
'540-559'="540<=SCORE<560"
'560-579'="560<=SCORE<580";
run;
proc print data=pf_lemon;
format scorefmt $scorefmt.;
run;
thank you for your guidance
I tried as you suggested, it works generallly except for the line with score low-539, pls see result below
input up down scorefmt $ sub_product $; datalines; 2 5 low-539 apple 3 2 540-559 lemon 4 0 560-579 melon run; proc format; value $scorefmt low-539="SCORE<540" 540-559="540<=SCORE<560" 560-579="560<=score<580"; RUN; proc print data=lemon; format scorefmt $scorefmt.; run;
Please post a link to the "example" source. If that is an example of what some site is using then it is either a very bad site, due to the number of errors that "example" generate, or you are skipping a lot of the actual example.
And what do you mean by "make it work"??? We have no idea what you would expect the result to be if or when it does "work".
@HeatherNewton wrote:
I read the doc but dont understand as the example is not complete. I try the code attached,
data pf_lemon; input scorefmt $; datalines; low-539 540-559 560-579 run; proc format data=pf_lemon; value scorefmt low-539 ="apple" 540-559="540<=SCORE<560" 560-579="560<=SCORE<580"; run; proc print data=pf_lemon; run;how can I make it work?
Your format is designed to combine single numeric values into ranges, so you should feed it such.
data pf_lemon;
input score;
datalines;
520
550
565
;
And then
proc print data=pf_lemon;
var score;
format score scorefmt.;
run;
Such range formats become very valuable when used with statistic procedures (FREQ, MEANS, TABULATE), as these will use the formatted values for grouping.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.