DATA Step, Macro, Functions and more

vvaluex

Reply
Super Contributor
Posts: 271

vvaluex

[ Edited ]

Hello,

 

This  example code was taken from stackoverflow.

 

data have;
input MERCH_NO      V01   M02  V08  M08  AMOUNT    PLAN $;
calc = input(vvaluex(plan),best12.) * amount;
put calc=;
datalines;
123456        2     2    1    1    100.00    V01     
456789        4     4    4    4    250.00    M08    
;;;;
run;

 

 

Can vvaluex be regarded as kind of macro variable resolution? In this example, value of V01 is 2.

 

I replicated the outout with this code.

 

%let V01 = 2;
%let M08 = 4;
data test;
set have;
calc= input(symget(plan),best.)*amount;
run;

Super User
Posts: 19,855

Re: vvaluex

Posted in reply to SAS_inquisitive

SAS_inquisitive wrote:

 

 

Can vvaluex be regarded as kind of macro variable resolution? In this example, value of V01 is 2.

 


No. VVALUEX returns the value of a variable. It can have nothing to do with macro variables. 

 

You create macro variables but don't use them so your example doesn't quite make sense.

Super Contributor
Posts: 271

Re: vvaluex

@Reeza wrote "You create macro variables but don't use them so your example doesn't quite make sense".

 

I am creating those macro variables and using symget function to get values. Basically, I was trying to do same thing as vvaluex function does using symget in this example.

Super User
Super User
Posts: 7,074

Re: vvaluex

[ Edited ]
Posted in reply to SAS_inquisitive

If you know your macro variable(s) contain numeric strings (all macro variables are character strings) you can use the SYMGETN() function to read it directly into a numeric variable and skip the INPUT() function call.

 

%let V01 = 2;
%let M08 = 4;
data want;
  input plan $ amount ;
  calc= symgetn(plan)*amount;
cards;
V01 3.4
M08 4.5
;

 

Ask a Question
Discussion stats
  • 3 replies
  • 109 views
  • 2 likes
  • 3 in conversation