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

 

when I use put statement to convert a numeric variable to character one, using the following code will make missings to '.', not blank. 

VSSTRESC=strip(put(VSRESPORRES,best.));

Then I need to use the following code to avoid '.' 

if VSRESPORRES ne . then  VSSTRESC=strip(put(VSRESPORRES,best.));
				else VSSTRESC='';

I have many such variables to convert. I wonder if there is an easier way to avoid it? 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

If you're lazy, you can use CATT, it does an automatic conversion, with no message in the log.

 

option missing='';

data class;
	set sashelp.class;

	if age=13 then
		weight=.;
run;

data check;
	set class;
	test1=catt(weight);
	test2=put(weight, best.);
run;

title 'Missing with space';

proc print data=check (obs=5);
run;

option missing=.;
title 'Missing with period';

proc print data=check(obs=5);
run;

 

 

View solution in original post

5 REPLIES 5
fengyuwuzu
Pyrite | Level 9

Thank you. Will this option statement affect the missing values of numeric varaibles in the same data step? 

Shmuel
Garnet | Level 18

the option options missing=' '; affects only how it is displayed.

Patrick
Opal | Level 21

As an alternative to the missing option which affects how missings are printed for all numerical variables, you can also define your own format as demontrated in the code below.

 

Also: To get your result left aligned you could use syntax <format name>.-L 

 

proc format;
  value MyBest(default=16)
  low-high=[best.]
  other=' ';
run;

data sample;
  VSRESPORRES=1;
  VSSTRESC=put(VSRESPORRES,MyBest.-L);
  output;
  VSRESPORRES=.;
  VSSTRESC=put(VSRESPORRES,MyBest.-L);
  output;
run;
Reeza
Super User

If you're lazy, you can use CATT, it does an automatic conversion, with no message in the log.

 

option missing='';

data class;
	set sashelp.class;

	if age=13 then
		weight=.;
run;

data check;
	set class;
	test1=catt(weight);
	test2=put(weight, best.);
run;

title 'Missing with space';

proc print data=check (obs=5);
run;

option missing=.;
title 'Missing with period';

proc print data=check(obs=5);
run;

 

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 6291 views
  • 2 likes
  • 4 in conversation