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

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
  • 2 replies
  • 1158 views
  • 0 likes
  • 3 in conversation