Hello
For each customer ID there is information of existence of 5 files (binary variables minus1,minus2,minus3,minus4,minus5).
There is also information of fist location customer appear.
I want to create want data set with following information:
For each customer ID:
Customer_First_Location (This column already exist in have data set)
First_File_Location (New column need to create)
status(New column need to create)
IF Customer_First_Location =First_File_Location then it is ok.
IF Customer_First_Location is after First_File_Location then it is not_ok
What is the way to create want data set?
data have;
input ID minus1 minus2 minus3 minus4 minus5 Customer_First_Location;
cards;
1 1 1 1 1 1 -1
2 0 1 0 0 1 -5
3 0 0 0 1 0 -4
4 0 0 0 0 1 .
;
Run;
Data want;
input ID Customer_First_Location First_File_Location status;
cards;
1 -1 -1 OK
2 -5 -2 Not_OK
3 -4 -4 OK
4 . -5 Not_OK
;
Run;
I took a guess at how to derive first_file_location:
data want ;
set have ;
length Status $8 ;
First_File_Location=whichn(1,of minus1-minus5) * -1 ;
if First_File_Location=Customer_First_Location then status='OK' ;
else status='Not_OK' ;
run ;
proc print ;
run ;
From your description:
>First_File_Location (New column need to create)
Nothing in this code indicates how that value is derived. Please explain how you are generating the value for First_File_Location.
You have not explained how First_File_Location is created.
I took a guess at how to derive first_file_location:
data want ;
set have ;
length Status $8 ;
First_File_Location=whichn(1,of minus1-minus5) * -1 ;
if First_File_Location=Customer_First_Location then status='OK' ;
else status='Not_OK' ;
run ;
proc print ;
run ;
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.
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.
Ready to level-up your skills? Choose your own adventure.