BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5
Hi

data all;
New_Variable=a,b,c,d,e,f,g,h,i... up ab,ac ...az
run;

I want them to create new datasets

data a;
set all;
if New_Variable='a' then output;
run;
...
.
.
.
data az;
set all;
if New_Variable='az' then output;
run;

like this based on this varaible new dataset should be created how can i do this.
and in the middle there are different names also in New_Variable 'acz','mnb'
and based this new datasets should be created.
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You can write a SAS macro that will execute for each SAS variable value. Suggest you write out your SAS DATA step so it works properly with one value, and then convert that DATA step into a macro where the "value" is substituted with a SAS macro variable -- the macro variable will be passed to the macro with each execution. One tip is that when referencing a macro variable as a literal, you enclose it in double-quote marks, not single-quotes.

To find all unique (DISTINCT) variable values, you may consider using the PROC SQL DICTIONARY members (or SAS view equivalent) - and with this information you could use macro code to generate macro invocations, once per data value.

Some highly recommended reading links provided below to get you started.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic/post:

macro programming introduction site:sas.com

proc sql dictionary members site:sas.com

generate code macro site:sas.com
R_Win
Calcite | Level 5
any one can help in this
polingjw
Quartz | Level 8
Try this code out:

proc sql noprint;
select distinct New_Variable into: all_values separated by ' '
from all;

select count(*) into: num_values from
(select distinct new_variable from all);
quit;

%macro create_datasets;
data &all_values;
set all;
%do i = 1 %to &num_values;
%let value = %scan(&all_values, &i);
if New_Variable = "&value" then output &value;
%end;
run;
%mend;
%create_datasets

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1031 views
  • 0 likes
  • 3 in conversation