BookmarkSubscribeRSS Feed
rohitkrishna
Calcite | Level 5

Hi All,

i have one issue regarding the sas code in my data have licnum it contains sum non numeric values like . $ A so i want to substitute the non numeric values to 0 plz kindly share the solution for the below issue 

 

data licnum;

infile datalines;

input @1 licno 10.;

datalines;

12..994432

980..e221..

;

run;

data numchg;

set licnum;

if licno = . then licno = 0;

run;

kindly give sum solution for the above issue and mainly it's a sasmainframe 

Thanks $ Regards 

Rohit

9 REPLIES 9
jklaverstijn
Rhodochrosite | Level 12

Your code is not wrong. You just use one of the many possible ways of mapping a missing to 0. These are a few other options:

data licnum;
infile datalines;
input @1 licno 10.;
/* Alternatives. Use one. */
licno = coalesce(licno, 0);
licno = sum(licno, 0);
if licno = . then licno = 0;
...

Hope this helps.

-- Jan.

rohitkrishna
Calcite | Level 5
Hi jklaverstijn
thanks for the quick replay
but i got some issue wt you posted, below error i got kindly look it once
LICNO = COALESCE(LICNO, 0);
________
________
________
68
68
68
OR 68-185: The function COALESCE is unknown, or cannot be accessed. kindly plz give some solution for that one
Thanks & Regard
Rohit
Kurt_Bremser
Super User

Please do always (as in

ALWAYS!

) post the whole log of a step, and do always (as in

ALWAYS!

) use this button for posting logs:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

 

We always ask this not because we're extremely bored, but because only whole logs help in diagnosing problems, and the </> window keeps the log as it is, without destroying the formatting.

rohitkrishna
Calcite | Level 5
HI KurtBremser,
Thanks for the Replay & sorry for what i posted, in the hurry manner i posted the hard code kindly ignore the mistake and give some of the solution above issue
Thanks & Regards
Rohit
jklaverstijn
Rhodochrosite | Level 12

You already have more than one solution. If COALESCE() doesn't work for you, use one of the other suggested methods:

 

Either:

 

LICNO = SUM(LICNO, 0);

Or:

 

if LICNO = . then LICNO=0;

You can put that in straight after the INPUT statement. No need for a second data step;

 

Hope this helps,

- Jan.

 

rohitkrishna
Calcite | Level 5
Hi jklaverstijn
Thanks for the quick response you're code working good but my expected o/p was not yet came i will share the log code
< DATA NEWLIC;
INFILE DATALINES;
INPUT @1 LICNO $10.;
IF LICNO = . THEN LICNO = 4;
DATALINES;
203....412
...3300421
9955..032.
;
RUN;
PROC PRINT DATA = NEWLIC;
RUN;
>
below the output i got
+++++++++++++++++++++++

Obs LICNO

1 4
2 4
3 4
+++++++++++++++++++++++++++++
but my expected output was
2030000412
0003300421
9955000320
i want to substitute non numeric to 0 like above . is the non numeric so i replaced with 0 in manual way kindly share some some solution for above one
Thanks & Regards
Rohit
PaigeMiller
Diamond | Level 26

Please share the log in the window that appears when you click on the </> icon, as requested

--
Paige Miller
jklaverstijn
Rhodochrosite | Level 12
Please do not change the code halfway without explanation. By reading using a character informat ($10. instead of 10.) you just changed the data type from numeric to character and any proposed solution may be all of sudden not applicable.
ChrisNZ
Tourmaline | Level 20

You must have a very old SAS version. Use one of the other suggestions.

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
  • 9 replies
  • 2175 views
  • 1 like
  • 5 in conversation