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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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