DATA Step, Macro, Functions and more

Macro to create new variable based on dataset name

Reply
N/A
Posts: 0

Macro to create new variable based on dataset name

Have 51 separate county datasets. Want to combine the 51 county datasets and create a variable "county name" based on the name of each dataset. Any suggestions?
SAS Super FREQ
Posts: 8,862

Re: Macro to create new variable based on dataset name

Posted in reply to deleted_user
Hi:
You could "macro-ize" something like the program example below. It is always best, however to start with a basic non-macro program and understand how it works before you convert it to a macro program.

cynthia
[pre]
data new;
set sashelp.prdsale(in=prdsale)
sashelp.prdsal2(in=prdsal2)
sashelp.prdsal3(in=prdsal3);
if prdsale=1 then filename = 'SASHELP.PRDSALE';
else if prdsal2 = 1 then filename = 'SASHELP.PRDSAL2';
else if prdsal3 = 1 then filename = 'SASHELP.PRDSAL3';
run;

ods listing;
proc freq data=new order=data;
tables filename;
run;
[/pre]
Valued Guide
Posts: 2,177

Re: Macro to create new variable based on dataset name

Posted in reply to deleted_user
if you have SAS92 use option INDSNAME= {VARname} see http://support.sas.com/kb/34/513.html .
SAS Super FREQ
Posts: 8,862

Re: Macro to create new variable based on dataset name

Thanks, Peter! I forget sometimes to point out the newer syntax.
cynthia
Ask a Question
Discussion stats
  • 3 replies
  • 149 views
  • 0 likes
  • 3 in conversation