BookmarkSubscribeRSS Feed
pavank
Quartz | Level 8
proc sql noprint;
  select name into :mvar1 - :mvar99  
  from sashelp.class
  ;
quit;

%macro printMvars();
  %do i=1 %to &sqlobs;
    %put &&mvar&i;
  %end;
%mend;
%printMvars()

i want to print list of values  line by line without macro do loop  using proc sql into clause block only 

required output

Alfred
Alice
Barbara
Carol
Henry
James
Jane
Janet
Jeffrey
John
Joyce
Judy
Louise
Mary
Philip
Robert
Ronald
Thomas
William

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

@pavank wrote:
proc sql noprint;
  select name into :mvar1 - :mvar99  
  from sashelp.class
  ;
quit;

%macro printMvars();
  %do i=1 %to &sqlobs;
    %put &&mvar&i;
  %end;
%mend;
%printMvars()

i want to print list of values  line by line without macro do loop  using proc sql into clause block only 

 


Why do you even specify using SQL and macros here? You make your programming harder by specifying it has to be done a certain way.

 

You could use PROC PRINT. You should be specifying the output you want, rather than using a specific PROC and the INTO clause.

--
Paige Miller
Tom
Super User Tom
Super User

If the goal is to list the name to the SAS log then skip the SQL and the macro code code.

data _null_;
  set sashelp.class;
  put name;
run;

If you have a set of macro variables with a common prefix and numeric suffix then you can also print them to the log using a data step.

data _null_;
  do i=1 to &sqlobs;
       value = symget(cats('mvar',i));
       put value;
  end;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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