Help using Base SAS procedures

REg:Output

Reply
Regular Contributor
Posts: 229

REg:Output

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.
Super Contributor
Super Contributor
Posts: 3,174

Re: REg:Output

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
Regular Contributor
Posts: 229

Re: REg:Output

any one can help in this
Regular Contributor
Posts: 171

Re: REg:Output

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
Ask a Question
Discussion stats
  • 3 replies
  • 198 views
  • 0 likes
  • 3 in conversation