%macro Mylist(); *Create Loop; %let totalofRecords =0; Data mydata; set readfromMyolddata nobs=nobs; Run; data _null_ ; set mydata nobs=nobs; call symput('totalofRecords', compress(nobs)); put nobs; stop; run; %do i = 1 %to &totalofRecords.; data _null_; set mydata ; if _n_ = &i; call symput ('abc_file', compress (abc_file)); run; %mend;
Blue Blue
@GN0001 wrote:
%macro Mylist(); *Create Loop; %let totalofRecords =0; Data mydata; set readfromMyolddata nobs=nobs; Run; data _null_ ; set mydata nobs=nobs; call symput('totalofRecords', compress(nobs)); put nobs; stop; run; %do i = 1 %to &totalofRecords.; data _null_; set mydata ; if _n_ = &i; call symput ('abc_file', compress (abc_file)); run; %mend;Blue Blue
As posted, this code does nothing except throwing a syntax ERROR. Read the log (Maxim 2), and fix the obvious problem first.
Consult the documentation (Maxim 1) of the DATA Statement to see what _NULL_ does.
Post the logs, and I will show you the problem and the reason.
The documentation has to be what it is because the software is extremely powerful. You need to start working with it, as it is the number one tool for success with SAS. 90% of my posts here consist of reading the doc for things I don't use regularly in my day-to-day work.
The error tells you: ERROR: There were 1 unclosed %DO statements. The macro MYLIST will not be compiled.
You have to add a macro %end; statement at the highlighted location below
Even if this macro becomes syntactically correct it doesn't look to me like doing much useful things but it certainly does unnecessary and wasteful things.
What is the purpose of this macro? What does it get used for?
@GN0001 wrote:
That is why I asked what it does.
Thanks,
Blue Blue
Sorry but the answer to such a generic question must be RTM.
"Explain me everything" starting with "how does SAS work" is may be a bit too much for this forum here.
So what do you think this message:
ERROR: There were 1 unclosed %DO statements.
tries to tell you?
Hint: study the documentation of the %DO Statement.
Now you made your code even worse.
1. remove the semicolon after the %do
2. the end is on macro level and requires a %. It needs to be %end;
%end? Or %mend?
Thanks,
blue blue
The first example in the documentation I linked has a complete example of a %DO loop, use it as a blueprint to avoid the simple mistakes.
I believe @Kurt_Bremser was referring to this documentation link from his earlier post, not the link to his maxims list.
Hint: study the documentation of the %DO Statement.
I suggest you study this thoroughly to understand how macro DO loops work.
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.
Ready to level-up your skills? Choose your own adventure.