BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
paddyb
Quartz | Level 8

i want to display all values in macro.its taking only 1st value

 

proc sql;
select mem ,name into:ds,:var  from dictionary.columns
where libname="RAW" and (name like '%AT' ') ;
quit;
proc sql;
select count(name)into:N from demo;
quit;


%macro loop(N,ds,var);
 %do i= 1 %to &N;
  %put "&ds" -"&var";
 

%end;

%mend;

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
proc sql;
select memname into:ds separated by " " from dictionary.columns
where libname="RAW" and (name like '%AT');
select name into:var separated by " " from dictionary.columns
where libname="RAW" and (name like '%AT');
quit;

%macro loop;
%do i = 1 %to %sysfunc(countw(&ds));
  %put %scan(&ds,&i) -%scan(&var,&i);
%end;
%mend;
%loop

View solution in original post

4 REPLIES 4
nehalsanghvi
Pyrite | Level 9

It's hard to provide a solution without any input data to work with or desired output data to look at. Can you send that along with the code?

 

You have specified only one macro variable per column you are selecting. So the query takes the values from the two columns from the first row only and puts them in those two macro variables.

 

Are you trying to print all column names from a dataset in one long string? Like this: ds1 has var1, var2, var3

 

Or do you want to print something like this in the log?

 

ds1 has var1

ds1 has var2

ds1 has var3

 

Here's a solution for the second option above:

proc sql;
select count(*) into :rowcount trimmed
from dictionary.columns
where libname="RAW"
and (name like '%AT') ;
quit;

proc sql;
select mem,name into :ds1-:ds&rowcount., :var1-:var&rowcount.
from dictionary.columns
where libname="RAW"
and (name like '%AT') ;
quit;

%macro loop;
 %do i= 1 %to &rowcount.;
  %put "&&ds&i" have "&&var&i";
%end;
%mend;

%loop;
paddyb
Quartz | Level 8

yes something similar.it worked.Thanks you

Kurt_Bremser
Super User
proc sql;
select memname into:ds separated by " " from dictionary.columns
where libname="RAW" and (name like '%AT');
select name into:var separated by " " from dictionary.columns
where libname="RAW" and (name like '%AT');
quit;

%macro loop;
%do i = 1 %to %sysfunc(countw(&ds));
  %put %scan(&ds,&i) -%scan(&var,&i);
%end;
%mend;
%loop
rogerjdeangelis
Barite | Level 11
I have not paid much attention to this post so maybe I am off base, but this seems to work

* create some data;
libname sd1 "d:/sd1";
data sd1.xat(keep=sat rat bat) sd1.zat(keep= hat fat);
  retain sat rat bat hat fat 0;
run;quit;

proc sql;
  select
     catx('-',memname,name)
  into
    :libnam separated by " "
  from
    dictionary.columns
  where
         libname="SD1"
     and (name like '%AT')
;quit;

 XAT-SAT
 XAT-RAT
 XAT-BAT
 ZAT-HAT
 ZAT-FAT


hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1732 views
  • 2 likes
  • 4 in conversation