The SAS Output Delivery System and reporting techniques

Help using dynamically generated data as input

Not applicable
Posts: 1

Help using dynamically generated data as input

Hi all,

I need a bit of help getting SAS to accept dynamically generated data in an input statement. Consider this data step (fictionary data):

data DEAdata;
format firms $12.;
input firms $ object con1-con9;
beta 1 2 &x 0 4 1 2 2 1 2
La0 1 2 3 0 4 1 2 2 1 2
Lb 1 2 3 0 4 1 2 2 1 2
Lc 1 2 3 0 4 1 2 2 1 2
Ld 1 2 3 0 4 1 2 2 1 2
Le 1 2 3 0 4 1 2 2 1 2
Lf 1 2 3 0 4 1 2 2 1 2
_RHS_ 1 2 3 0 4 1 2 2 1 2

My problem is the "x" variable in the first row which is a global variable(hence the &) that is assigned a value dynamically prior to this data step when the script is run. But SAS does not accept that I place the variable directly in the datalines as above. It is deemed invalid data in the log. Can anyone help me on this one? I can only come up with one possible explanation. Earlier in the script I use the "call symput" routine in order to make "x" a global variable. As far as I can tell this routine converts any numeric data into character data meaning that I am trying to input character data datastep written above?
Hope someone can help me. Thanks.
Posts: 9,371

Re: Help using dynamically generated data as input

Hi, Kim:
This does not really seem like an ODS question, but more of a DATA step INFILE/INPUT statement question.

As you noted, the macro variable &x is NOT resolved in the input buffer, so when your INPUT statement tries to read it from the buffer, SAS sees non-numeric characters where it is expecting to see numeric characters. In fact, the documentation on the SAS Macro facility states that:
"You can define and use macro variables anywhere in SAS programs, except within data lines." Since &x is a macro variable reference you cannot "technically" use it within your data lines.

If all you need to do is change con2 to the value of &x for the "beta" row (when _n_ = 1), then this would work in your existing program (as you have presented the hypothetical data):
if firms = 'beta' and _n_ = 1 then do;
con2 = input("&x",8.0);

If &x is in the global symbol table when the DATA step program executes, then the value for &x will be translated from character to numeric by the INPUT function (different from the INPUT statement). You will still see a warning in the LOG that there was a problem trying to read &x as a number.

I worry a bit about your usage of the term "script" and your reference to using CALL SYMPUT to set the value of X. Generally, you use CALL SYMPUT within a DATA step program to set the value of a macro variable (in the global symbol table) from some value within a DATA step program at execution time. This implies to me, somehow that the value of the macro variable &x might be changing based on the value of some variable in some -other- DATA step program.

A DATA step program has similarities to scripting languages (like JavaScript, PHP or VB), but I would not consider a DATA step program to be a script. Also, your DATA step program (where you use call symput), could itself be contained within a SAS macro program -- and if this is the case, then, the above solution might not be the best one for your ENTIRE program, including the piece with the CALL SYMPUT. If you are not familiar with SAS macro programming conventions, you might consider contacting Tech Support with the entire text of your program to make sure that you are using the Macro facility in the best way. It seems unusual (to me) that a single variable value in "raw" datalines or a "raw" data file would change based on a macro variable.

To contact Tech Support, go to:

Not applicable
Posts: 0

Re: Help using dynamically generated data as input

When I had a problem like this under z/OS, I used the RESOLVE function:


Of course, you then need to split up the record into the separate variables! Maybe the SCAN function could be used to do this.
Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation