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

Hi SAS Community, 

 

I want to create a set of features based on a date index- that is, a set of features based on a date on one line per ID key. 

 

This is the data:

data.PNG

 

 

What I want it to look like: 

desired_output.PNG

 

This is the code I came up with:

 

data x;
set x;

if date_field = '30SEP2018:00:00:00.000'dt then SEP2018_BAL= amount;
else if date_field = '31OCT2018:00:00:00.000'dt then OCT2018_BAL= amount;
else if date_field = '30NOV2018:00:00:00.000'dt then NOV2018_BAL= amount;
else if date_field = '31DEC2018:00:00:00.000'dt then DEC2018_BAL= amount;
else if date_field = '31JAN2019:00:00:00.000'dt then JAN2019_BAL= amount;
else if date_field = '28FEB2019:00:00:00.000'dt then FEB2019_BAL= amount;


run;

And this is the output I am getting, which is not ideal:

 

current_output.PNG

 

Let me know if you need any more info from me. Thank you! 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Hi @sassing and welcome to the SAS Community 🙂

 

Here's how I would do it

 

data have;
retain ID_key "a1_1234";
input amount date_field :anydtdtm22.;
format date_field datetime22.;
datalines;
710937.5  30SEP2018:00:00:00.000
713653.38 31OCT2018:00:00:00.000
705974.23 30NOV2018:00:00:00.000
704847.1  31DEC2018:00:00:00.000
704016.17 31JAN2019:00:00:00.000
703178.11 28FEB2019:00:00:00.000
;

data temp;
    set have;
    vn=cats(put(datepart(date_field), monyy7.), '_BAL');
run;

proc transpose data=temp out=want(drop=_:);
    by ID_key;
    id vn;
    var amount;
run;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Hi @sassing and welcome to the SAS Community 🙂

 

Here's how I would do it

 

data have;
retain ID_key "a1_1234";
input amount date_field :anydtdtm22.;
format date_field datetime22.;
datalines;
710937.5  30SEP2018:00:00:00.000
713653.38 31OCT2018:00:00:00.000
705974.23 30NOV2018:00:00:00.000
704847.1  31DEC2018:00:00:00.000
704016.17 31JAN2019:00:00:00.000
703178.11 28FEB2019:00:00:00.000
;

data temp;
    set have;
    vn=cats(put(datepart(date_field), monyy7.), '_BAL');
run;

proc transpose data=temp out=want(drop=_:);
    by ID_key;
    id vn;
    var amount;
run;
sassing
Calcite | Level 5

@PeterClemmensen, THANK YOU SO MUCH! THIS WORKS! 

 

Have a good day further.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 558 views
  • 1 like
  • 2 in conversation