I want to rename the same three variables across a group of files. Thought %str would work, but it didn't
27 %let ren=%str(pbp_a_hnumber=H_Number pbp_a_plan_identifier=Plan_ID segment_id=Segment_ID);
28
27 %let ren=%str(pbp_a_hnumber=H_Number pbp_a_plan_identifier=Plan_ID segment_id=Segment_ID);
_
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
29 Data pbp_b1a;
30 set D107342.pbp_b1a (keep=&keepvars pbp_b1a_auth_yn
___
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
31 rename=(
32 %bquote(&ren)
33 pbp_b1a_auth_yn=inpatient_acute_auth
34 ));
35 run;
36
You don't need %str macro function there, there is nothing to mask.
E.g.
%let ren= (age=age_group sex=sex_group height=height_group);
%put &=ren;
data have;
set sashelp.class (rename=&ren);
run;
1 %let ren= (pbp_a_hnumber=H_Number pbp_a_plan_identifier=Plan_ID 1 ! segment_id=Segment_ID); 2 3 %put &=ren; REN=(pbp_a_hnumber=H_Number pbp_a_plan_identifier=Plan_ID segment_id=Segment_ID) 4 %let ren= (age=age_group sex=sex_group height=height_group); 5 6 %put &=ren; REN=(age=age_group sex=sex_group height=height_group) 7 data have; 8 set sashelp.class (rename=&ren); 9 run; NOTE: There were 19 observations read from the data set SASHELP.CLASS. NOTE: The data set WORK.HAVE has 19 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.02 seconds cpu time 0.03 seconds
I would double check the syntax. As you see in example above equal signs passes into macro var without issue.
You don't need %str macro function there, there is nothing to mask.
E.g.
%let ren= (age=age_group sex=sex_group height=height_group);
%put &=ren;
data have;
set sashelp.class (rename=&ren);
run;
1 %let ren= (pbp_a_hnumber=H_Number pbp_a_plan_identifier=Plan_ID 1 ! segment_id=Segment_ID); 2 3 %put &=ren; REN=(pbp_a_hnumber=H_Number pbp_a_plan_identifier=Plan_ID segment_id=Segment_ID) 4 %let ren= (age=age_group sex=sex_group height=height_group); 5 6 %put &=ren; REN=(age=age_group sex=sex_group height=height_group) 7 data have; 8 set sashelp.class (rename=&ren); 9 run; NOTE: There were 19 observations read from the data set SASHELP.CLASS. NOTE: The data set WORK.HAVE has 19 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.02 seconds cpu time 0.03 seconds
I would double check the syntax. As you see in example above equal signs passes into macro var without issue.
Missing some bits. For you to get that error on line 27 something else is likely going before line 27 that is making that %let have a problem. Also, please post LOG text into a text box opened on the forum with the </> icon above the main message window. That will have the diagnostic characters, such as the underscore that appears above the 180, in the proper position relative to the code.
Strongly suggest that you show the code submitted before this along with this code.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.