BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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 ;
The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

View solution in original post

3 REPLIES 3
SASJedi
SAS Super FREQ

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.

Check out my Jedi SAS Tricks for SAS Users
PaigeMiller
Diamond | Level 26

You have not explained how First_File_Location is created.

--
Paige Miller
Quentin
Super User

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 ;
The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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
  • 1121 views
  • 1 like
  • 4 in conversation