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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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