DATA Step, Macro, Functions and more

How to iteratively process datasets for one procedure

Reply
Contributor
Posts: 43

How to iteratively process datasets for one procedure

[ Edited ]

How to process all datasets in a library iteratively.

 

Below is what I'm trying but getting error.

 

%macro spDS;
%local dsCnt;

proc sql ;
   select count(*)into :dsCnt from sashelp.vtable where libname='SERETIDE';
quit;

    %let i=1;

    %do %while (&i. <= &dsCnt.);
        
        data _null_;
            set sashelp.vtable (where=(libname='SERETIDE') firstobs=1 obs=1 );
            call symput("inlibref",strip(libname));
            call symput("inmember",strip(memname));
            call symput("outlibref",strip(strans));
            put _all_;
        run;
        
        proc sort data=&inlibref..&inmember. out= &outlibref..&inmember.
                    (drop = subjectstatus form formentrydate subjectvisitformid);
                     by subjectid;
                run;        
     %let i=%eval(&i.+1);
    %end;
    
%mend;
Trusted Advisor
Posts: 1,918

Re: How to iteratively process datasets for one procedure

Is it simply fixing one line of code? Like this:

 

set sashelp.vtable (where=(libname='SERETIDE') firstobs=&i obs=&i );

If that's not it then I think to get any meaningful answer, you'd need to tell us what error you are getting. Show us!!!! Gives us details. Lots and lots of details.

Super User
Posts: 19,815

Re: How to iteratively process datasets for one procedure


krisraa wrote:

 

Below is what I'm trying but getting error.

 


 

There's no error shown in your post. 

Contributor
Posts: 43

Re: How to iteratively process datasets for one procedure

here you go.

Trusted Advisor
Posts: 1,918

Re: How to iteratively process datasets for one procedure

It says right there in the SAS log that STRANS is uninitialized ... the variable doesn't exist. You have to fix that problem.

Super User
Posts: 19,815

Re: How to iteratively process datasets for one procedure

STEP 1. READ YOUR LOG. 

 

It has an error:

 

 NOTE: Line generated by the macro variable "OUTLIBREF". 

56          .             _             22             76
 ERROR 22-322: Expecting a name. ERROR 76-322: Syntax error, statement will be ignored.

 

So somethings wrong with the OUTLIBREF assignment. 

STEP 2. Check the OUTLIBREF assignment

 

call symput("outlibref",strip(strans));

 

STEP 3. Check if this is working, or why not. Hint, STRANS isn't a variable on the SASHELP.VTABLE. 

 

In future posts, please include the log if you have an error. This isn't the first time we've had to ask for this either....

Contributor
Posts: 43

Re: How to iteratively process datasets for one procedure

Thanks will ensure going fwd.

 

Now I have removed the outlibref from the code and hardcoded the "strans" reference in the Proc Sort. procedure.

 

Now getting error as attached.

Super User
Posts: 19,815

Re: How to iteratively process datasets for one procedure

Post the errors directly into the forum.

 

Add the macro debugging options and rerun your macro so we can see the actual code.

And include only the section with the errors because I don't want to scan through 10 pages of your log. 

 

Some resources on macro debugging:

http://www.lexjansen.com/nesug/nesug10/ff/ff10.pdf

http://www.lexjansen.com/scsug/2013/Strategies-and-Techniques-for-Debugging-SAS-Program-Errors-and-W...

Contributor
Posts: 43

Re: How to iteratively process datasets for one procedure

The iterations are complete and datasets were sorted but after the last iteration the below error is occuring.

 

 MLOGIC(SPDS):  %LET (variable name is I)
 MLOGIC(SPDS):  %DO %WHILE(&i. <= &dsCnt.) condition is TRUE; loop will iterate again.
 
 NOTE: There were 1 observations read from the data set SASHELP.VTABLE.
       WHERE libname='SERETIDE';
 NOTE: DATA statement used (Total process time):
       real time           0.05 seconds
       cpu time            0.03 seconds
       
 
 
 NOTE: There were 660 observations read from the data set SERETIDE.VS.
 NOTE: The data set STRANS.VS has 660 observations and 14 variables.
 NOTE: PROCEDURE SORT used (Total process time):
       real time           0.03 seconds
       cpu time            0.00 seconds
       
 
 MLOGIC(SPDS):  %LET (variable name is I)
 180: LINE and COLUMN cannot be determined.
 NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where 
       the error has occurred.
 ERROR 180-322: Statement is not valid or it is used out of proper order.
 MLOGIC(SPDS):  %DO %WHILE() condition is FALSE; loop will not iterate again.
 MLOGIC(SPDS):  Ending execution.
 87         
 88         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 100        
Super User
Posts: 19,815

Re: How to iteratively process datasets for one procedure

options mprint symbolgen mlogic;


Those are the options you need to show the full log. 

Contributor
Posts: 43

Re: How to iteratively process datasets for one procedure

 MLOGIC(SPDS):  %LET (variable name is I)
 SYMBOLGEN:  Macro variable I resolves to 23
 SYMBOLGEN:  Macro variable I resolves to 24
 SYMBOLGEN:  Macro variable DSCNT resolves to       23
 180: LINE and COLUMN cannot be determined.
 NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where 
       the error has occurred.
 ERROR 180-322: Statement is not valid or it is used out of proper order.
 MLOGIC(SPDS):  %DO %WHILE() condition is FALSE; loop will not iterate again.
 MLOGIC(SPDS):  Ending execution.
 58         
 59         
 60         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 SYMBOLGEN:  Macro variable GRAPHTERM resolves to GOPTIONS NOACCESSIBLE;
 72         
Super User
Posts: 19,815

Re: How to iteratively process datasets for one procedure

 SYMBOLGEN:  Macro variable I resolves to 23
 SYMBOLGEN:  Macro variable I resolves to 24
 SYMBOLGEN:  Macro variable DSCNT resolves to       23

 

That doesn't make sense....check what the 23/24th entry in the data set is and why it may be causing an issue. 

Contributor
Posts: 43

Re: How to iteratively process datasets for one procedure

There is only 23 datasets in the library, but it also contains other files like .txt, .zip, .sas files as well.

 

Is that a problem ?

 

if yes how do i explicitly say only to sort sas7bdat files

Super User
Posts: 19,815

Re: How to iteratively process datasets for one procedure

Check the data set...and your loop conditions. 

What happens if you use a straight %do loop rather than do while?

 

Contributor
Posts: 43

Re: How to iteratively process datasets for one procedure

IF i use Do loop then i'm getting the same error.

Ask a Question
Discussion stats
  • 44 replies
  • 228 views
  • 7 likes
  • 4 in conversation