BookmarkSubscribeRSS Feed
RandyStan
Fluorite | Level 6

Dear All

 

My data is as follows

 

ID                IDA

CO              CO

I                    I

HUF           HUF

.

B               B

 

I want to fill in the two missing values in IDA

 

ID                IDA

CO              CO

I                    I

HUF           HUF

.                 NO_CAT

.                 NO_CAT

B               B

 

I wrote these lines

 

Data want; set have;

if IDA = '.' then do ; IDA = NO_CAT: end ;

run;

 

What mistake am I making

 

Randy

4 REPLIES 4
unison
Lapis Lazuli | Level 10

NO_CAT must be a string. In addition to that, missing for character values are indicated with '' rather than '.' 

 

if IDA = '' then IDA = 'NO_CAT';

-unison

-unison
SASKiwi
PROC Star

Maybe this? Not sure if there is a real dot in IDA or not. If not then remove it.

Data want; set have;

if IDA = '.' then do ; 
IDA = 'NO_CAT';
end ;

run;

 

JJP1
Pyrite | Level 9

Hi @RandyStan ,

i followed as per @SASKiwi  it is working fine.

If it is character variable then we should not use . just simply ' ';please have  a look on below code and it is working as expected.

Data have;
input IDA $3. IDA1 $6.;
datalines;
ID    IDA
CO  CO
I   I
HUF HUF
.    
. 
B   B
;
run;

Data want; 
set have;

if IDA = ' ' then do IDA1 = 'NO_CAT';
end;


run;
sustagens
Pyrite | Level 9
Check if the variable IDA is of character- or numeric- type.

Null values in character variables are assigned a blank ('')
while in numeric variables it is a period (.)

Hence if IDA is numeric, your condition will just be:
if IDA = .

But if IDA is character, your condition will be:
if IDA = ''

The only time you will need to use:
if IDA = '.' is when a character variable intentionally has a period for a value.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 4 replies
  • 698 views
  • 0 likes
  • 5 in conversation