BookmarkSubscribeRSS Feed
GN0001
Barite | Level 11
%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

Blue Blue
14 REPLIES 14
Kurt_Bremser
Super User

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

GN0001
Barite | Level 11
Hello,
Thanks for the response.
I can't see the obvious problem.
Documentations are very convoluted most of the time and it is hard to understand.
Respectfully,
Blue Blue
Blue Blue
Kurt_Bremser
Super User

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.

GN0001
Barite | Level 11
This is my log:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 %macro Mylist();
74 *Create Loop;
75
76 %let totalofRecords =0;
77
78 Data mydata;
79 set readfromMyolddata nobs=nobs;
80 Run;
81
82 data _null_ ;
83 set mydata nobs=nobs;
84 call symput('totalofRecords', compress(nobs));
85 put nobs;
86 stop;
87 run;
88
89 %do i = 1 %to &totalofRecords.;
90
91 data _null_;
92 set mydata ;
93 if _n_ = &i;
94 call symput ('abc_file', compress (abc_file));
95 run;
96
97 %mend;
ERROR: There were 1 unclosed %DO statements. The macro MYLIST will not be compiled.
ERROR: A dummy macro will be compiled.
98

Regards,
Blue Blue
Blue Blue
Patrick
Opal | Level 21

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

Patrick_0-1620343305861.png

 

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
Barite | Level 11
That is why I asked what it does.
Thanks,
Blue Blue
Blue Blue
Patrick
Opal | Level 21

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

GN0001
Barite | Level 11
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 %macro Mylist();
74 *Create Loop;
75
76 %let totalofRecords =0;
77
78 Data mydata;
79 set readfromMyolddata nobs=nobs;
80 Run;
81
82 data _null_ ;
83 set mydata nobs=nobs;
84 call symput('totalofRecords', compress(nobs));
85 put nobs;
86 stop;
87 run;
88
89 %do;
90 %i = 1 %to &totalofRecords.;
ERROR: Improper use of macro reserved word TO.
91
92 data _null_;
93 set mydata ;
94 if _n_ = &i;
95 call symput ('abc_file', compress (abc_file));
96 run;
97 end;
98 %mend;
ERROR: There were 1 unclosed %DO statements. The macro MYLIST will not be compiled.
ERROR: A dummy macro will be compiled.
99
100 ;
101
102 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
114

Regards,
blue blue;
Blue Blue
Patrick
Opal | Level 21

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;

 

Patrick_0-1620343933232.png

 

GN0001
Barite | Level 11

%end? Or %mend?

Thanks,

blue blue

Blue Blue
GN0001
Barite | Level 11
Hello KurtBremser,
I have no idea where you are referring to.
On documentation, I can see maxims and that's about it.
One thing that is interesting, on my phone, I can see links to topics that I am excited for. I can't see it on my computer.
Thanks for all,
Blue Blue
Blue Blue
SASKiwi
PROC Star

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.  

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 14 replies
  • 884 views
  • 3 likes
  • 4 in conversation