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


sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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