BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DmytroYermak
Lapis Lazuli | Level 10

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!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
gamotte
Rhodochrosite | Level 12
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

6 REPLIES 6
gamotte
Rhodochrosite | Level 12
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);
DmytroYermak
Lapis Lazuli | Level 10
Definitely! Thank you!
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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...

DmytroYermak
Lapis Lazuli | Level 10

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

DmytroYermak
Lapis Lazuli | Level 10
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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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