DATA Step, Macro, Functions and more

why couldn't create a macro var in the data step

Reply
Frequent Contributor
Frequent Contributor
Posts: 81

why couldn't create a macro var in the data step

Hi
According to my below coding. It doesn' t create macro var numrec. but if I place 'put numrec' instead of 'call symput('num', numrec)' it output the value 5; Please note that I am using version 8.2. thanks so much in advance for your help.



data temp;
input x 1.;
cards;
1
2
3
4
5
;
run;


data _null_;
call symput('numrec', numrec);
stop;
set temp nobs=numrec;
run;

%put 'value ' &numrec;

Thanks

Inp
Super Contributor
Posts: 474

Re: why couldn't create a macro var in the data step

It works for me (v9.1.3 SP4)
[pre]
NOTE: SAS initialization used:
real time 16.67 seconds
cpu time 1.48 seconds

1 data temp;
2 input x 1.;
3 cards;

NOTE: The data set WORK.TEMP has 5 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 1.54 seconds
cpu time 0.00 seconds


9 ;
10 run;
11
12
13 data _null_;
14 call symput('numrec', numrec);
15 stop;
16 set temp nobs=numrec;
17 run;

NOTE: Numeric values have been converted to character values at the places given by: (Line)Smiley SadColumn).
14:23
NOTE: DATA statement used (Total process time):
real time 0.25 seconds
cpu time 0.00 seconds


18
19 %put 'value ' &numrec;
'value ' 5
[/pre]
Cheers from Portugal.

Daniel Santos @ www.cgd.pt
Valued Guide
Posts: 2,177

Re: why couldn't create a macro var in the data step

your code worked for me and created the macro variable successfully with a value of 5[pre]446 %put 'value ' &numrec;
'value ' 5[/pre]
but perhaps that's because I'm running SAS9.2

Why are you running such an old version of SAS?

PeterC
Frequent Contributor
Frequent Contributor
Posts: 81

Re: why couldn't create a macro var in the data step

It worked for SAS 9.2 which I have on my pc But my maiframe has SAS 8.2.

Thanks

Inp
Valued Guide
Posts: 2,177

Re: why couldn't create a macro var in the data step

it might help reveal the issues if you could post the sas log from the mainframe run of the program
Frequent Contributor
Frequent Contributor
Posts: 81

Re: why couldn't create a macro var in the data step

12 DATA _NULL_;
13 CALL SYMPUT('NUMREC', NUMREC);
______
______
______
546
546
546
NOTE 546-185: THE VARIABLE NUMREC MAY BE UNINITIALIZED.

14 STOP;
15 SET TEMP NOBS=NUMREC;
16 RUN;

NOTE: NUMERIC VALUES HAVE BEEN CONVERTED TO CHARACTER VALUES AT THE PLACES GIVEN BY: (LINE)Smiley SadCOLUMN).
13:23
NOTE: THE DATA STATEMENT USED 0.00 CPU SECONDS AND 8620K.
Super Contributor
Posts: 474

Re: why couldn't create a macro var in the data step

I would suspect of a "weird" character somewhere in your source code.

Try to type the same code into a new source and run it.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
Super Contributor
Super Contributor
Posts: 3,174

Re: why couldn't create a macro var in the data step

Posted in reply to DanielSantos
Suggest you share *ALL* of the SAS log from your mainframe batch job. And include a %PUT _ALL_; to dump all user SAS macro variables declared.

And consider that the message you received is a SAS NOTE, not an ERROR.

And, you definitely want to get up on a supported SAS version on z/OS (IBM mainframe), either SAS 9.2 Phase 2 (recommended) or at least SAS 9.1.3 SP4 (plus HOTFIXes).

Scott Barry
SBBWorks, Inc.
Valued Guide
Posts: 2,177

Re: why couldn't create a macro var in the data step

could it be a feature of SAS82 : not populating the NOBS= variable until the SET statement is executed, rather than compiled?
Ask a Question
Discussion stats
  • 8 replies
  • 195 views
  • 0 likes
  • 4 in conversation