Hi Everyone,
I use the code below to create temporary command and it create a trailing space in the id value.
it should be like
id='F2_w1_w2_N_3109'; instead of
id='F2_w1_w2_N_3109 ';
The temporary full command is below
IF brk25_roc94 =0 then do; id='F2_w1_w2_N_3109 '; output;end;
IF brk25_roc94 =0 then do; id='F2_w1_w2_N_3107 '; output;end;
Is there any way to avoid that space?
Thank you for your help.
HHCFX
filename tmp temp;
data null;
set setupid_check end=last_cond;
file tmp;
put 'IF ' a_name '=' a_value ' then do; id=' "'" id "'" '; output;end;' ;
options source2;run;
Another method if the trailing increases by 1,2 or unknown spaces:
data setupid_check;
a_name = 'brk25_roc94';
id = 'F2_w1_w2_N_3107';
a_value = 0;
run;
data null;
set setupid_check (rename=(id = id_)) end=last_cond;
id = cats("'",id_,"'");
file print;
put 'IF ' a_name '=' a_value ' then do; id=' id '; output;end;';
options source2;
run;
On the one hand, it's difficult to imagine how a trailing space will hurt anything. If the length of ID is set anyplace in the code, that length will be in effect whether there is a trailing space or not. However, you can get rid of it if needed by changing this line:
put 'IF ' a_name '=' a_value ' then do; id=' "'" id "'" ';
To remove the trailing space, back up and write over it:
put 'IF ' a_name '=' a_value ' then do; id=' "'" id +(-1) "'" ';
Another method if the trailing increases by 1,2 or unknown spaces:
data setupid_check;
a_name = 'brk25_roc94';
id = 'F2_w1_w2_N_3107';
a_value = 0;
run;
data null;
set setupid_check (rename=(id = id_)) end=last_cond;
id = cats("'",id_,"'");
file print;
put 'IF ' a_name '=' a_value ' then do; id=' id '; output;end;';
options source2;
run;
Thank you everyone for helping.
HHCFX
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.