BookmarkSubscribeRSS Feed
EmersonK
Calcite | Level 5
Can I use CALL SYMPUT inside a loop to create multiple variables for use later?
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Yes, but do consider that each SAS MACRO variable would need to be unique-named (possibly using a numeric, incrementing suffix-character). I suppose the next question back to the OP is: what are you attempting to accomplish with generating "n" unique-named macro variables in a DATA step (presuming that is what you were referencing with "...inside a do loop")?

Scott Barry
SBBWorks, Inc.
data_null__
Jade | Level 19
As noted by SBB you can indeed create lots of uniquely named macro variables using CALL SYMPUT and a data step. My question to you is WHY? What are you going to do with all these variables.

My rule is thumb is "don't put data into macro variables". Data sets are for data and data sets + data/proc steps are very powerful. You can paint yourself into a corner with data in macro variables.

I'm not trying to be flip, you seem to be new to SAS or at least this forum Posts: 2, and I doubt you need all those macro variables.
Peter_C
Rhodochrosite | Level 12
> Can I use CALL SYMPUT inside a loop to create
> multiple variables for use later?

yes you can.
I have found it most useful when a bunch of parameters are loaded from an excel range containing effectively, name/value pairs
data _null_ ;
set excel.parameter_range ;
call symputx( name, value ) ;
run ;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
For the benefit of the OP, I encourage Peter.C to explain how such "a bunch of parameters" might be used in a SAS application, ideally with some specific purpose?

Possibly, these incoming data-values from an Excel document are being loaded to drive a SAS application with SAS macro variables, specifically those macro variables &xxxxxxxx by the value of "name" variable and containing a value represented by the current observation variable value for "value").

Honestly, just because you can isn't always a good use of exploiting a feature or capability -- much to my own dog's personal indulgence dismay.

Scott Barry
SBBWorks, Inc.
Peter_C
Rhodochrosite | Level 12
Scott
You have described very well how these parameters are used in the application!
The application used these parameters to support a daily liquidity reporting process for a global banking group. Each subsidiary needs to provide it's report in the standard layout but each has many basic, simple differences. It was these differences where the parameter sheet in excel provide flexibility for the on- going support and use of the application by non-SAS users.
. Seldom did fundamental parameters change for a subsidiary but these did not need to be in code although they were prototyped with %let. Other parameters did change occasionally. Since these were quite different subsidiaries their data sources varied a lot. Supporting that, a set of parameters defined the frequency location and name pattern for the inputs One parameter even signalled that certain intermediate data files which could be useful for ad-hoc reporting should be kept.
I stand by my statement that the data step with call symputx() was very straightforward and effective.
peterC

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 1347 views
  • 0 likes
  • 4 in conversation