BookmarkSubscribeRSS Feed
phil27
Calcite | Level 5
Hello,
I call a first macro to calculate &type.

Then I would like to update a field of a table from the macro; I try to use SYMGET to do it.

data out;
set In;
%TestsFormat(code, 'NUM', '1','3', code_);
run;


%Macro TestsFormat(MyVarIn, MyType, MyValueOk, MyValueNok, MyVarOut) / store;
%verif_num_char_date(&MyVarIn);
%If &type ne &MyType %Then &MyVarOut=symget("MyValueNok"); %Else &MyVarOut=symget("MyValueOk");
%Mend;

%macro verif_num_char_date(MyVar) / store;
%global type;
DATA _NULL_;
var=input("&MyVar" ,?? COMMA8.);
IF var ne . then call symput('type','NUM');
ELSE do;
var=input("&MyVar",ANYDTDTM.);
if var ne . then call symput('type','DAT');
else call symput('type','CHAR');
end;
run;
%mend;

I have the following Error message :

NOTE: Generated line by the macro variable "MYVAROUT".
1 code_
-----
180

ERROR 180-322: Incorrect Instruction

If someone has an idea, it would be great.

Thanks. Message was edited by: phil27
3 REPLIES 3
SAS_user
Calcite | Level 5
I think the problem is here:
your macro creates something like this statemets:

data out;
set In;

data _null_;
/* your code */
run;
code_ =
run;

you can use options mprint; to see what your macro creates
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
It's best to start with a more basic DATA step execution to exercise your DATA step (and / or PROC steps too) logic. Then look at how you can inject macro language constructs for more flexibility.

Firstly, I see a DATA _NULL_ statement followed directly by an assignment that uses the INPUT function, however there would be no variable value assigned. I suspect that you thought that you could use a mix of SYMPUT and SYMGET within the same DATA step, then inserted the DATA _NULL_ when it didn't work for you.

Basically there are fundamental issues with your technique - one that attempts to mix macro language (a compilation time event) and DATA step processing.

Scott Barry
SBBWorks, Inc.


SAS Macro Language: Reference, DATA Step Functions for Macros
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a003167025.htm

Intermediate and Advanced SAS® Macros
Steven First, Katie Ronk, Systems Seminar Consultants, Madison, WI
http://www2.sas.com/proceedings/sugi31/107-31.pdf
ChrisNZ
Tourmaline | Level 20
As said above, many problems with your code.
You need to get up to speed with the macro language, and might want to consider proper training.
In this case, think of the macro language as a code generator.

This will work:

[pre]
%Macro TestsFormat(MyVarIn, MyType, MyValueOk, MyValueNok, MyVarOut);
VAR=input(&MyVarIn ,?? COMMA8.);
if VAR ne . then TYPE='NUM';
else do;
VAR=input(&MyVarIn,?? ANYDTDTM.);
TYPE=ifc( VAR ne . , 'DAT', 'CHAR');
end;
&MyVarOut=ifc(TYPE = &MyType, &MyValueOk, &MyValueNok);
%Mend;
[/pre][pre]

data OUT;
set SASHELP.CLASS;
AGEC=put(age,3.);
%TestsFormat(AGEC, 'NUM', '1','3', code_);
run;

[/pre]

Note that a date like 20091231 will end up as NUM here.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 900 views
  • 0 likes
  • 4 in conversation