BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

If data contains only digits or digits with decimals then would like to create a column "want" and assign those records to the column. tried compress function but it is compressing decimals too. 
Rawdata
UNKNOWN
37.5/25
37.5-25
0.25
25
10
1000IU


Rawdata         want             
UNKNOWN                     
37.5/25                            
0.25                0.25
25                    25
10                   10
1000IU                             

3 REPLIES 3
Astounding
PROC Star

This should do it:

 

want = input(rawdata, ??16.);

 

Since you didn't specify, this approach assumes you would like the new variable to be numeric, not character. 

SASPhile
Quartz | Level 8

Yes want is only Numeric an would like want_char with remaining values

Astounding
PROC Star

If you would like to add WANT_CHAR as well, it's easy enough:

 

want = input(rawdata, ??16.);
if want = . then want_char = rawdata;
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
  • 3 replies
  • 1734 views
  • 0 likes
  • 2 in conversation