Hi All
I have 10 data sets and it is save in my library as
dt_city_01; (data sets name)
dt_city_02;
dt_city_03; ............. so on to
dt_city_10.
I want to assign city into 1 macro variable and 01,02,03(so on to 10) into other macro variable.....
can any 1 help me out..
thanks in advance.
@vThanu wrote:
Hi All
I have 10 data sets and it is save in my library as
dt_city_01; (data sets name)
dt_city_02;
dt_city_03; ............. so on to
dt_city_10.
I want to assign city into 1 macro variable and 01,02,03(so on to 10) into other macro variable.....
Show us the results that you want. I'm afraid I don't find your explanation clear.
Also, where are these 10 data set names located? Are they in a text file, or an Excel file, or a SAS data set, or did you type them into your SAS program, or somewhere else?
SAS data sets (data set name itself saved as dt_city_01..... dt_city_10)....
This creates your dataset names:
%macro mymac(dspart=,number=);
%do i = 1 %to &number.;
%let dsnum=%sysfunc(putn(&i.,z2.));
%let dsname=dt_&dspart._&dsnum.;
%put dsname=&dsname.;
%end;
%mend;
%mymac(dspart=city,number=10)
Please find the attached document for your reference....
As per the attached document, I want to create Two macro variables - 1 for City and other for 01
Please post relevant information as text, many won't open office documents.
If you want to set a macro variable from the names of datasets, use a "select into" from dictionary.tables in proc sql.
I believe most people will understand what you have but it's a bit hard to understand what you want. What's normally really helpful is to get a desired result - like you giving us the name and content of the macro variables you're after in detail.
Below a code sample which hopefully will provide you the hints you need to make things working for you. Run the code and inspect the SAS log.
data work.dt_city_01 work.dt_city_02 work.dt_city_03;
set sashelp.class;
run;
proc sql noprint;
select
memname, memname
into :ds_name_mvar1-:ds_name_mvar99, :ds_name_list separated by ' '
from dictionary.tables
where libname='WORK' and memname like 'DT^_CITY^_%' escape '^'
;
quit;
%put &=sqlobs;
%put &=ds_name_list;
%macro PutCreatedMVars();
%put &=sqlobs;
%do i=1 %to &sqlobs;
%put ds_name_mvar&i: &&ds_name_mvar&i;
%end;
%mend;
%PutCreatedMVars()
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.