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

Hello everyone,

 

I am dealing with a quite messy data and I want to convert them into numeric.

in the same variable, I have value of say: $90 , $90.25 , 90.28, 1,012 , $1,253.25

I mean, any combination among $ and comma (,)

 

My approach is to compress "$" and "," and then create new variable but clearly, it doesn't work.

 

Please, any help is very much appreciated.

 

HC

 

data have;
input var1 $ var2 $;
datalines;
$84.12 $1,000.20
$1,184.12 1,000.20
84 $55
;run;
data have; set have;
var1=input(compress(var1,'$'),best12.); *I am thinking about an IF var1 contain $ then do, but I dont know how to;
var1=input(compress(var1,','),best12.);

var2=input(compress(var2,'$'),best12.);
var2=input(compress(var2,','),best12.);
run;
data want; set have;
drop var1 var2;
var1_new=Input(var1 ,best12.);
var2_new=Input(var2 ,best12.);
run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ShiroAmada
Lapis Lazuli | Level 10

Try this...

 

data WANT;
  set HAVE;
 var1_new=input(compress(var1,"$,"),8.);
 var2_new=input(compress(var2,"$,"),8.);
RUN;

Hope it helps.

View solution in original post

3 REPLIES 3
ShiroAmada
Lapis Lazuli | Level 10

Try this...

 

data WANT;
  set HAVE;
 var1_new=input(compress(var1,"$,"),8.);
 var2_new=input(compress(var2,"$,"),8.);
RUN;

Hope it helps.

kiranv_
Rhodochrosite | Level 12

if you reading the data all you need to do is give informat commaw.d. You can try something like below

 

data have;
input var1:comma10.2 var2:comma10.2;
datalines;
$84.12 $1,000.20
$1,184.12 1,000.20
84 $55
;
ChrisNZ
Tourmaline | Level 20

Like this?

data WANT;
  set HAVE;
  VARN1=input(VAR1,dollar12.); 
  VARN2=input(VAR2,dollar12.);
run;

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
  • 720 views
  • 0 likes
  • 4 in conversation