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

Hello, 

Every one 

 

Have : 

 

var1 

 

+2 

3+ 

-1

4-

34.56

Zero

NA

 

want 

 

var1  var2 

 

+2       +2

3+       3+

-1       -1

4-       4-

34.56   .

Zero   Zero

NA      NA

 

I am converting character to numeric, I am using 

 

input(strip(var1), ??  best.);

 

but problem is when use this syntx I am not able to get var2 correct for +3,+2, or such values but I am getting correct values for 3+,2+ ,zero, NA 

 

my data has +3 and I need it  +3 in to var2. 

 

Thanks in advance 

PS
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Less convoluted

 


data have;
input var1 $;
cards;
+2 
3+ 
-1
4-
34.56
Zero
NA
;

data want;
set have;
if notdigit(compress(strip(var1),'.')) then var2=var1;
run;

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Is the requirement that var2 has to be numeric? You don't specifically state that. Leaving var2 as character makes everything simple.

 

If so, then you would need to create a specific picture format for your situation.

--
Paige Miller
shahparth260
Quartz | Level 8

Thanks for responding on the question. Yes I think I forget to mention about that. 

 

Var1 is in Character 

Var2 is also in Character I just dont want to see any Numeric values in to this such as 9,4.5, 8.937, so on 

 

Thanks again.

PS
novinosrin
Tourmaline | Level 20

@shahparth260 

 


data have;
input var1 $;
cards;
+2 
3+ 
-1
4-
34.56
Zero
NA
;

data want;
set have;
var2=ifc(notdigit(compress(strip(var1),'.')),var1,' ');
run;
novinosrin
Tourmaline | Level 20

Less convoluted

 


data have;
input var1 $;
cards;
+2 
3+ 
-1
4-
34.56
Zero
NA
;

data want;
set have;
if notdigit(compress(strip(var1),'.')) then var2=var1;
run;
shahparth260
Quartz | Level 8

@novinosrin  Thanks for posting solution on that. I really appreciated for simple version however I figured for IFC but may be it helps for novice. Thanks again keep helping 🙂 🙂 

PS

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 625 views
  • 3 likes
  • 3 in conversation