DATA Step, Macro, Functions and more

Call symputx and infile datalines

Accepted Solution Solved
Reply
Regular Contributor
Posts: 214
Accepted Solution

Call symputx and infile datalines

Hi all,

 

Could you please help to tune-up the program with 'call symputx'. The macrovariables are not initialized and I don't understand the reason:

options mprint mlogic;
data denoms;
 length PARAMN 8 PARAMCD DENOM $200;
 infile datalines dsd dlm = "@";
 input PARAMN PARAMCD DENOM;
 call symputx(compress(PARAMCD||put(_N_,best.)),PARAMCD);
 call symputx(compress(DENOM||put(_N_,best.)),DENOM);
datalines;
11 @ AUCIFO	@	0
12 @ AUCLST	@	0
13 @ CMAX	@	0
14 @ TMAX	@	2
15 @ LAMZ	@	4
16 @ LAMZHL	@	1
21 @ CLFO	@	2
22 @ VZFO	@	0
31 @ CLO	@	2
32 @ VZO	@	0
33 @ VSSO	@	0
34 @ AUMCLST	@	0
35 @ AUMCIFO	@	0
36 @ MRTIVLST	@	1
41 @ AUCTAU	@	0
42 @ CMIN	@	0
43 @ CTROUGH	@	0
44 @ CAVG	@	0
;
run;

Thank you!

 

 


Accepted Solutions
Solution
‎02-15-2018 03:50 AM
Super Contributor
Posts: 359

Re: Call symputx and infile datalines

Posted in reply to DmytroYermak
Hello,

You forgot the quotes in the first argument of symputx

call symputx(compress("PARAMCD"||put(_N_,best.)),PARAMCD);
call symputx(compress("DENOM"||put(_N_,best.)),DENOM);

View solution in original post


All Replies
Solution
‎02-15-2018 03:50 AM
Super Contributor
Posts: 359

Re: Call symputx and infile datalines

Posted in reply to DmytroYermak
Hello,

You forgot the quotes in the first argument of symputx

call symputx(compress("PARAMCD"||put(_N_,best.)),PARAMCD);
call symputx(compress("DENOM"||put(_N_,best.)),DENOM);
Regular Contributor
Posts: 214

Re: Call symputx and infile datalines

Definitely! Thank you!
Super User
Super User
Posts: 9,855

Re: Call symputx and infile datalines

Posted in reply to DmytroYermak

Thats really not a good way to go, remember macro is not a replacement for Base SAS.  You have data in one table, you need to use this in another table, then you merge the data from one onto another.  This is a very simple and common process that is used in almost every program, do not try to ignore that and write macro code to do the same thing.  Thousands of lines of dodgy macro code, or a simple merge statement by paramcd...

Regular Contributor
Posts: 214

Re: Call symputx and infile datalines

[ Edited ]

Hi RW9,

 

I completely agree that code should not be complicated unless absolutely necessary. But please have a look where the macrovariables are used further:

 

%macro num_to_char;
%do i = 1 %to 18;
  if PARAMCD in ("&&PARAMCD&i.") then do;

QVAL_Mean_C = put(QVAL_Mean,16.%eval(&&DENOM&i.+1)-L); QVAL_StdDev_C = put(QVAL_StdDev,16.%eval(&&DENOM&i.+2)-L); QVAL_Min_C = put(QVAL_Min,16.&&DENOM&i.-L); QVAL_Median_C = put(QVAL_Median,16.%eval(&&DENOM&i.+1)-L); QVAL_Max_C = put(QVAL_Max,16.&&DENOM&i.-L);
end; %end; %mend num_to_char; data tableX ; format QVAL_Mean_C QVAL_StdDev_C QVAL_Min_C QVAL_Median_C QVAL_Max_C $200.; set proc_mean_results; NObs_C = put(NObs,16.0-L); %macro num_to_char; run;

 

The list of parameters or the number of decimals can be changed anytime. I hope that using of the approach outlined can help to react faster.

Super User
Super User
Posts: 9,855

Re: Call symputx and infile datalines

Posted in reply to DmytroYermak

Exactly the code I would avoid like the plague, lists of data, loops all kinds of things, all of which will go wrong at some point.  An example of using merge:

data want (drop=denom);
  merge lab_data param_data;
  by paramcd;
  qval_stddev_c=putn(qval_stddev,16,denom);
  ...
run;

So much simpler and expandable as any dataset is.  Also note that by the use of paramcd I assume your using either LAB model, LB domain, or an ADaM BDS structure.  For LAB, LB precision should already be a variable, and for ADaM, this should be present in some form or other, perhaps already rounded?

Regular Contributor
Posts: 214

Re: Call symputx and infile datalines

Thank you for the code. Actually I didn't know about "putn" where one can declare decimals using varialbes value. Your approach is definitely simpler.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 174 views
  • 1 like
  • 3 in conversation