SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
vThanu
Calcite | Level 5

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.

7 REPLIES 7
PaigeMiller
Diamond | Level 26

@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?

--
Paige Miller
vThanu
Calcite | Level 5

SAS data sets (data set name itself saved as dt_city_01..... dt_city_10)....

 

 

 

Kurt_Bremser
Super User

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)
vThanu
Calcite | Level 5

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

 

 

 

andreas_lds
Jade | Level 19

Please post relevant information as text, many won't open office documents.

Patrick
Opal | Level 21

@vThanu 

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()

sas-innovate-white.png

Join us for our biggest event of the year!

Four days of inspiring keynotes, product reveals, hands-on learning opportunities, deep-dive demos, and peer-led breakouts. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1417 views
  • 0 likes
  • 5 in conversation