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?

 

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

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