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;

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 6570 views
  • 2 likes
  • 4 in conversation