BookmarkSubscribeRSS Feed
rebelde52
Fluorite | Level 6

Hello.

 

I want to use an IF-THEN statement followed by a By statement to create a new variable with a selected date given my IF-THEN statement. It seemed to select my conditions and create a new variable. However, when I do a proc print; the date I selected and my new column returns as a " . " instead of the date it originally had. 

 

How can I fix this? is this a formatting issue? I did do a proc contents and both the old and new date variable are NUM so I'm kind of confused on the issue. 

 

Below is my code and my output. 

 

data compare;
set combined;
if Pending='YES' then new_date_num = old_date_num;
by name;
run;

name

old_date_num

date

Pending

new_date_num

FM1

23264

9/11/2023

NO

.

FM1

23264

9/11/2023

NO

.

FM1

23264

9/11/2023

NO

.

FM1

23264

9/11/2023

NO

.

FM1

23271

9/18/2023

NO

.

FM1

.

9/11/2023

YES

.

3 REPLIES 3
A_Kh
Barite | Level 11

Hi, 
Your code seems to return a valid value which is missing when pending='yes'; 

rebelde52
Fluorite | Level 6
before this data step that value was actually 23264
Tom
Super User Tom
Super User

I want to use an IF-THEN statement followed by a By statement 

That does not make any sense.  BY statement follow SET/MERGE/UPDATE statements in a DATA step.  Or follow the PROC statement in a PROC step.

 

Since for the observations where Pending='YES' have a missing value of old_date_num where do you want to get a non-missing value for new_date_num ?

 

Do you want to remember one of the values of new_date_num from one of the previous observations?

 

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