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

Hi,

I used an array to convert the numeric variables  to character variables. None of the numeric variables had any formats associated with it but all had a length of 8. The value for non-missing numeric values was 1 and the value of missing numeric values was a period. I applied the character fomat $40. as I need to reformat the values later. However, after conversion of the numeric to character the missing values are being retained as periods and not blanks. Is there a way to have them as blanks after the conversion? Please let me know as soon as possible. Thanks.

Array _numeric(*)

var2

var3

var4

var5

var6;

 

Array _character(*) $ 40

var2_C

var3_C

var4_C

var5_C

var6_C

DO i=1 to dim(_numeric);

_character(i) = PUT(_numeric(i),8.);

END;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

A simple change to one statement:

 

if _numeric(i) > . then _character(i) = PUT(_numeric(i),8.);

View solution in original post

3 REPLIES 3
Astounding
PROC Star

A simple change to one statement:

 

if _numeric(i) > . then _character(i) = PUT(_numeric(i),8.);

Haikuo
Onyx | Level 15

@Astounding, chance is very slim, yet possible:

 

data test;
	input num;
	char=put(num,8.);
	char_1=ifc(num>.,put(num,8.),'');
	char_2=ifc(not missing(num),put(num,8.),'');
	cards;
100
.
._
.A
.Z
;
Tom
Super User Tom
Super User

You can change the setting of the MISSING option.  Also be careful how you convert to character. Your current use of the PUT() function will cause your character variables to have leading spaces.

2183  %let save=%sysfunc(quote(%qsysfunc(getoption(missing))));
2184  options missing=' ';
2185  data _null_;
2186    do x=0,1,.,123.456 ;
2187      c1=put(x,8.);
2188      c2=cats(x);
2189      put x= (c1 c2) (= :$quote.) ;
2190    end;
2191  run;

x=0 c1="       0" c2="0"
x=1 c1="       1" c2="1"
x= c1="" c2=""
x=123.456 c1="     123" c2="123.456"
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


2192  options missing=&save;

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 8643 views
  • 3 likes
  • 4 in conversation