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

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 ;

View solution in original post

3 REPLIES 3
SASJedi
Ammonite | Level 13

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 ;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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