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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.