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
PROC Star

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 ;
Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.

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
PROC Star

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 ;
Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 461 views
  • 1 like
  • 4 in conversation