Hi Guys,
I have a quick question can we create macro variables using :INTO clause in subqueries
select distinct names into :names1-:names&total from
(select names,Count(distinct names) into :total from sample)
can we use :into in a subquery as shown above
The answer is NO.
RTM-->
As @novinosrin says, no.
But the "fix" is insted of subquery create a separate query that generates just the macro variables you attempt from the subquery. But that may not be needed at all.
proc sql noprint; select distinct names into :names1-:names9999 from sample ; quit;
If you do not 9999 distinct names on the names1-namesXXX are created.
The automatic SAS macro variable &sqlobs will have the count of returned items in the last previous query.
So
%let NameCount = &sqlobs;
immediately after the Proc SQL will capture that count.
If you suspect you need more than 9999 macro variables (a real bad sign IMHO) increase the count.
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.
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.