BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASAna
Quartz | Level 8

Hi SAS USers,

 

MANUAL_FILES is not being assigned with DSET values , It is coming as blank.

 

Below macro i am collecting all datasets & combining them by tilda delimiter in DSET & splitting them in UNIX_FILES Dataset & trying to read one by one in MANUAL_FILES macro variable. 

 

%MACRO INIT_PULL;


libname mydata '/unixpath/';

proc sql;
select memName into:DSET separated by '~'
from dictionary.tables
where libname='MYDATA' and memtype='DATA';
Quit;

%PUT &DSET;

 

DATA UNIX_FILES;
Length MANUAL_FILES $32767;
%LET i=1;
%do %while (&i <= (%length(compress(&DSET,~,k))) +1);
%let MANUAL_FILES = %scan(&DSET,&i,~);
%let i = %eval(&i+1);
%end;
RUN;

 

%MEND INIT_PULL;

 

%INIT_PULL;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The DATA step that you wrapped around your macro %DO loop is not doing anything and should be removed.  If you want the data in a dataset then just skip the macro variable and have PROC SQL create the dataset for you.

 

If the goal is to use macro logic to pull names one by one out of the list in the macro variable then just use a normal iterative %DO loop. Note that PROC SQL will tell you how many records it processed with the macro variable SQLOBS so you can set the upperbound of your %DO loop.

 

proc sql noprint;
  select memName
    into  : dset separated by '~'
    from dictionary.tables
    where libname='MYDATA' and memtype='DATA'
  ;
%let ndset=&sqlobs;
quit;

%do i=1 %to &ndset;
  %let MANUAL_FILES = %scan(&DSET,&i,~);
  %* Do something here ;
  %put &=i &=manual_files ;
%end;

 

View solution in original post

10 REPLIES 10
Reeza
Super User

I don't understand what your second step is trying to accomplish.

Can you explain in plain language?

Shmuel
Garnet | Level 18

Pay attention - is this a typo ?

     select memName intoSmiley Very HappySET separated by '~'

     ...

     %PUT &DSET;

 

 

(and what is the smily comes for ?)

Reeza
Super User

@Shmuel That's the forum converting the text. Colon Capital D -> 😄

 

Shmuel
Garnet | Level 18

Thank you @Reeza

It means that original text was (I just aded a blank seperator)

    select memName into : DSET separated by '~'

Shmuel
Garnet | Level 18

Then, macro is not needed:

 

libname mydata '/unixpath/';

proc sql;
select memName intoSmiley Very HappySET separated by '~'
from dictionary.tables
where libname='MYDATA' and memtype='DATA';
Quit;

%PUT &DSET;

 

DATA UNIX_FILES;
       Length MANUAL_FILES $32767;

       do i=1 to countw("&DSET" , '~');
            file_x  = scan("&DSET" , i , '~' );
       end;
RUN;

SASAna
Quartz | Level 8

Hi,

 

thats ":D" came as smiley , but i was trying to move collect all the datasets into a variable called DSET seperated by :

 

 

@Reeza :  this datasetep i am using it for looping & splitting as i have to pass one by one datasets & moving into a macro variable manual_files for furthur process. Manual_file is not getting resolved. Not sure if it is &DSET ?

 

 

DATA UNIX_FILES;
Length MANUAL_FILES $32767;
%LET i=1;
%do %while (&i <= (%length(compress(&DSET,~,k))) +1);    (" I created DSET in previous step which has around 30 datasets                                                                                                                                                         sepeated by tilda  "~")
%let MANUAL_FILES = %scan(&DSET,&i,~);
%let i = %eval(&i+1);
%end;
RUN;

Tom
Super User Tom
Super User

The data step is neither looping or splitting. Since the macro logic is not generating any actual SAS code here is your full data step.

DATA UNIX_FILES;
Length MANUAL_FILES $32767;
RUN;

So it will make one observation dataset with one empty string variable.

Patrick
Opal | Level 21

Tell us what your end goal is, what you need as a result of your code, i.e. is this about combining 30 tables with the same structure into a single table?

Tom
Super User Tom
Super User

The DATA step that you wrapped around your macro %DO loop is not doing anything and should be removed.  If you want the data in a dataset then just skip the macro variable and have PROC SQL create the dataset for you.

 

If the goal is to use macro logic to pull names one by one out of the list in the macro variable then just use a normal iterative %DO loop. Note that PROC SQL will tell you how many records it processed with the macro variable SQLOBS so you can set the upperbound of your %DO loop.

 

proc sql noprint;
  select memName
    into  : dset separated by '~'
    from dictionary.tables
    where libname='MYDATA' and memtype='DATA'
  ;
%let ndset=&sqlobs;
quit;

%do i=1 %to &ndset;
  %let MANUAL_FILES = %scan(&DSET,&i,~);
  %* Do something here ;
  %put &=i &=manual_files ;
%end;

 

SASAna
Quartz | Level 8
Thanks Tom. It worked very well , you have helped me minimize many un-necessary codes too .

Thanks again

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!

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.

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
  • 10 replies
  • 1079 views
  • 0 likes
  • 5 in conversation