BookmarkSubscribeRSS Feed
subrat1
Fluorite | Level 6

I have formula in Excel as given below:

=IF(ISNUMBER(VALUE(N2)),TEXT(N2,"#.###"),N2)

 

 

How to covert this function in Excel  in SAS program

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

And what have you tried?

if in excel = if in sas.

isnumber can be reversed as anyalpha.

the two different returns can be controlled by if /else if, or ifc or ifn.  

Without test data in the form of a datastep and what you want out at the end, that is as far as I can go.

want=ifc(anyalpha(value)=0,text,n2);
SuryaKiran
Meteorite | Level 14

There are several function to accomplish the task, but choosing the right one depends on the data you have and your required output. Some times you may have to use multiple function to achieve it.

 

For Example: If you look at the code I'm using Compress function with "d" modifier to add all digits, "$" and "." to be removed. In this case you can find which variables values have only digits (Note: In case if you have some special symbols add them to list). Then MISSING() function to find a missing values (Here if missing then numeric values,else char values). INPUT to convert to numeric and PUT to convert to Character with the format you wish.

 

 

data have;
input char $;
datalines;
ABC1
$1
num2
5.55
55
;
run;
data want;
set have;
IF missing(compress(char,'$.','d')) then Char=PUT(INPUT(compress(char,'$','a'),8.),4.3);
run;

Hope this make sense. If not then provide some example data types you have.

 

Thanks,
Suryakiran

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1836 views
  • 0 likes
  • 3 in conversation