BookmarkSubscribeRSS Feed
KDLiwen
Calcite | Level 5

I have created a list of macro variables in a PROC SQL without error.  When I create the macro variables I have a list of parameters (costval) that I have created previosuly in the job.  I cannot hard code these values because they may change and I want the flexibility to pick up any new ones that are added.  I am having trouble getting the syntax right to get these values to resolve in a DATA step further down the line.  How do I get these costvals to resolve?  Any help would be appreciated.

 

proc sql noprint ;
  select %do i = 1 %to &costvars ;
    sum(CC_&&costval&i),
  %end ;
    count(*), sum(TotalGTM)
   into
  %do i = 1 %to &costvars ;
    :ccE&&costval&i,
  %end ;
  :ccETotal, :ccEmptyGTM
  from work.emptycc ;
quit ;

2 REPLIES 2
Astounding
PROC Star

You might find it easier if you change the names of the macro variables that SQL creates.

 

You have:

 

:ccE&&costval&i,

 

Try:

 

:ccE_&i,

 

You would still have &costval1 - &costvalN that tells you how the numbers relate to the original field names.

 

Good luck.

ballardw
Super User

Hard to tell what may be going on. Have you tried using options mprint or  adding a %put _user_; statement after the proc sql to see what your code is resolving to?

Are you getting any errors? If so what are they?

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