BookmarkSubscribeRSS Feed
1239
Calcite | Level 5

Hi All,

 

I am trying to find out Non missing from both Character and Numeric Data Type and then overwrite date as shown below from SAS 9.4 EG. I wanted to know is there any simple code to achieve quickly as I have this kind of requirement for multiple datasets?

 

Thanks for your help!

data want;
    set test;
    if missing(bsasdt) and (not missing(bsdostr) or not missing(bsdorea_1) or not missing(bsdorea_2) 
or not missing(bsdorea_3) or not missing(bsdorea_4) or not missing(status)) then bsasdt = created_dt;
	else bsasdt = bsasdt;
run;
 

SAS Attributes of Test dataset shown below:

1239_4-1645167465068.png

 

 

 

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

The Cmiss Function counts missing values of both numeric and character type variables. 

 

So something like below. (Untested since no test data)

 

data want;
    set test;
    if missing(bsasdt) and cmiss(bsdostr, bsdorea_1 - bsdorea_4, status) < 6 then bsasdt = created_dt;
run;
ballardw
Super User

I don't think that code does what you think you want it to.

Given the description of your variable BSASDT as character length one and Created_dt as some SAS date value I created similar values and did the assignment "Bsasdt = Created_dt" and this what my log shows:

1    data example;
2       /* first three lines create variables with description
3        similar to your data set*/
4       length bsasdt $ 1;
5       created_dt= today();
6       format created_dt date11.;
7       bsasdt=created_dt;
8    run;

NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
      7:11
NOTE: Invalid character data, created_dt=22694.00 , at line 7 column 11.
bsasdt=* created_dt=18-FEB-2022 _ERROR_=1 _N_=1

So unless you really want BSASDT to have * as the result you need to do a lot more work.

 

I suspect what every you did to read or create this particular data set named Test, if not others, did not result in what you intended. I would guess that the data set either resulted directly from Proc Import where the column used for BSASDT was blank in the first few rows of data or was created from a set created in that manner. A character length of 1 is what Import will assign for blanks.

 

I strongly suspect if you read the data correctly using a data step then you completely bypass the issue of some of these character and numeric. If you have multiple data sets that are supposed to have the same structure, which is sort of implied  about using similar code for all of them, have you verified that they have in fact been created with 1) the same variables and 2) that the variables are of the same types and lengths?

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
  • 1920 views
  • 1 like
  • 3 in conversation