BookmarkSubscribeRSS Feed
puregallus
Calcite | Level 5

Hi all, I'm trying to create a table for each version of a variable in a parent table. Currently I am using the following code:

 

%let TABLE=libref.tablename
%let COLUMN=columnname

proc sql noprint;
select distinct
cat("DATA out_",compress(&COLUMN.,'','kad'),
";set &TABLE.(where=(&COLUMN.='" ,&COLUMN.,
" ')); run;") length=500 into :allsteps separated by ';'
from &TABLE.;
quit;
%macro runSteps;
&allsteps.;
%mend;
%runSteps;

My problem is that I would like to limit to rows of the output tables to a certain number say 5. But I can't quite figure out how to fit obsout into this code. Putting it in the proc sql statement just prevents the looping of of the runSteps macro.

 

Thanks for your help.

1 REPLY 1
gamotte
Rhodochrosite | Level 12

Hello,

 

with call execute in a data step :

 

%let table=sashelp.class;
%let column=age;

data _NULL_;
input age;
call execute(cats('data out_',&column.,'; set &table.; where &column.=',&column.,'; if _N_ le 3; run;'));
cards;
12
13
14
15
16
;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1028 views
  • 0 likes
  • 2 in conversation