BookmarkSubscribeRSS Feed
mhoward2
Obsidian | Level 7
This is a great write up, helps illustrate the concept well, thanks for sharing!!!!
Ksharp
Super User

The most efficient way is using IF-ELSE in a data step,once for all, no need PROC SORT firstly.

 

data have;
input color $ val;
datalines;
Green 5
Green 8
Green 3
Green 1
Green 10
Yellow 9
Yellow 2
Yellow 6
Yellow 8
Yellow 12
Yellow 5
Yellow 8
Purple 5
Purple 2
Purple 6
;
proc freq data=have noprint;
table color/out=color nopercent nocum;
run;
data _null_;
if _n_=1 then do;
 call execute('data ');
 do until(last);
   set color end=last;
   call execute(color);
 end;
 call execute(';set have; select(color);');
end;
set color end=eof;
call execute(cat('when("',color,'") output ',color,';'));
if eof then call execute('otherwise;end;run;');
run;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 16 replies
  • 4799 views
  • 1 like
  • 6 in conversation