BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Rhodochrosite | Level 12

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;
1 ACCEPTED SOLUTION

Accepted Solutions
qoit
Pyrite | Level 9

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;

View solution in original post

4 REPLIES 4
Astounding
PROC Star

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) "'"	';
qoit
Pyrite | Level 9

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;
Ksharp
Super User
put 'IF ' a_name '=' a_value ' then do; id=' "'" id +(-1) "'" '; output;end;' ;
hhchenfx
Rhodochrosite | Level 12

Thank you everyone for helping.

HHCFX

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1098 views
  • 2 likes
  • 4 in conversation