- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Everyone,
I copied a code from SAS book and somehow it is not working.
The idea is to save all Name in a macro variable and print it one by one.
Can you please help?
Thanks,
Harry
proc sql noprint;
select name into :namelist1-
from sashelp.class
; quit;
%macro doprint;
%do i=1 %to &sqlobs;
%put name &i is &namelist1&i;
%end;
%mend;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%macro doprint;
%do i=1 %to &sqlobs;
%put name &i is &&namelist&i;
%end;
%mend;
%doprint
But I must ask, why do you need macro variables and macro do loops for this? Why not simply this:
proc sql;
select name from sashelp.class
; quit;
which is soooooo much easier than printing via a macro do loop.
Or why not simply this:
proc print data=sashelp.class;
var name;
run;
which is soooooo much easier than printing via a macro do loop.
You should not resort to macros just to print data that is already in a SAS data set, this is completely unnecessary and counter-productive.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%macro doprint;
%do i=1 %to &sqlobs;
%put name &i is &&namelist&i;
%end;
%mend;
%doprint
But I must ask, why do you need macro variables and macro do loops for this? Why not simply this:
proc sql;
select name from sashelp.class
; quit;
which is soooooo much easier than printing via a macro do loop.
Or why not simply this:
proc print data=sashelp.class;
var name;
run;
which is soooooo much easier than printing via a macro do loop.
You should not resort to macros just to print data that is already in a SAS data set, this is completely unnecessary and counter-productive.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Paige,
I am learning that Macro code from SAS book.
But still, you code only give me the first row (i=1).
Thanks,
Harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I just tried @PaigeMiller's code, and it seems to be working for me. Make sure you run both steps together, one right after another. Maybe you could just cut and paste the follwing code into an editor window:
proc sql noprint;
select name into :namelist1 -
from sashelp.class;
quit;
%macro doprint;
%do i=1 %to &sqlobs;
%put name &i is &&namelist&i;
%end;
%mend;
%DoPrint;
Make sure that "namelist" in "&&namelist&i" is spelled correctly. Originally, you spelled it "namelist1" which will not work properly.
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for helping.
I got it!
Harry