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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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