DATA Step, Macro, Functions and more

Can I use CALL SYMPUT for this?

Reply
New Contributor
Posts: 2

Can I use CALL SYMPUT for this?

Can I use CALL SYMPUT inside a loop to create multiple variables for use later?
Super Contributor
Super Contributor
Posts: 3,174

Re: Can I use CALL SYMPUT for this?

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.
Respected Advisor
Posts: 3,777

Re: Can I use CALL SYMPUT for this?

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.
Valued Guide
Posts: 2,175

Re: Can I use CALL SYMPUT for this?

> 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 ;
Super Contributor
Super Contributor
Posts: 3,174

Re: Can I use CALL SYMPUT for this?

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.
Valued Guide
Posts: 2,175

Re: Can I use CALL SYMPUT for this?

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
Ask a Question
Discussion stats
  • 5 replies
  • 345 views
  • 0 likes
  • 4 in conversation