BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Angel_Saenz
Quartz | Level 8

I have 3 dataset with different information date, example:

DATASETNAME ID PAYMENTS INFORMATIONDATE

DS1                      1    0                   31Jan2016

DS1                      2    1                   31Jan2016

DS2                      1    2                   29Feb2016

DS2                      2    1                   29Feb2016

DS3                      1    1                   31Mar2016

DS3                      2    1                   31Mar2016

 

I want  RESULT:

ID PAYMENTDS1 PAYMENTDS2 PAYMENTDS3 VECTOR 

1          0                        2                          1                  021

2          1                        1                          1                  111

 

(using data step, not proc sql if is possible)

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Look at PROC TRANSPOSE and then use a CATT to calculate vector. 

Or can you guarantee that you'll have only 3 DS? I'm assuming this is a simplified example. 

 

data have;
    format DATASETNAME $4. informationdate date9.;
    informat informationdate date9.;
    input DATASETNAME $ ID PAYMENTS INFORMATIONDATE;
    cards;
DS1                      1    0                   31Jan2016
DS1                      2    1                   31Jan2016
DS2                      1    2                   29Feb2016
DS2                      2    1                   29Feb2016
DS3                      1    1                   31Mar2016
DS3                      2    1                   31Mar2016
;
run;

proc sort data=have;
    by id datasetname;
run;

proc transpose data=have out=flipped prefix=PAYMENTS;
    by id;
    id datasetname;
    var payments;
run;

data want;
    set flipped;
    vector=catt(of payment:);
run;

View solution in original post

4 REPLIES 4
Reeza
Super User

Look at PROC TRANSPOSE and then use a CATT to calculate vector. 

Or can you guarantee that you'll have only 3 DS? I'm assuming this is a simplified example. 

 

data have;
    format DATASETNAME $4. informationdate date9.;
    informat informationdate date9.;
    input DATASETNAME $ ID PAYMENTS INFORMATIONDATE;
    cards;
DS1                      1    0                   31Jan2016
DS1                      2    1                   31Jan2016
DS2                      1    2                   29Feb2016
DS2                      2    1                   29Feb2016
DS3                      1    1                   31Mar2016
DS3                      2    1                   31Mar2016
;
run;

proc sort data=have;
    by id datasetname;
run;

proc transpose data=have out=flipped prefix=PAYMENTS;
    by id;
    id datasetname;
    var payments;
run;

data want;
    set flipped;
    vector=catt(of payment:);
run;
Angel_Saenz
Quartz | Level 8

Thank you Reeza that works very good, just two more questions:

 

1. like pyments are numeric some obs are nulls so is a . and vector is like .1 .012 and my vector is char, how can I do to my vector is numeric?

 

2. how can I quit the var _NAME_ in mi dataset result?

 

thank you

Reeza
Super User

1. What do you want it to look like? Repost sample data that accurately reflects your situation. 

2. DROP _name_;

Angel_Saenz
Quartz | Level 8

thank you Reeza I solved that situation

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 688 views
  • 2 likes
  • 2 in conversation