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

I am using PROC Transpose and following error occurs ID values occurs twice same in the BY group.

 

Proc SORT DATA=TEST OUT=TEST1;

BY DATE;

RUN;

 

Proc Transpose data=test1 out = test2;

BY DATE;

ID DATE;

VAR APPLICANT_NO Days_Past_Due;

RUN;

 

Applicant_NoDays_Past_DueDate
15701Nov2019
15701Dec2019
15801Jan2020
15601Feb2020
15601Mar2020
18601Apr2020
15701Apr2021
15701May2021
18701Jun2021
18801Jul2021
18801Aug2021
18801Sep2021
25701Mar2020
25701Apr2020
28701Apr2021
28801May2021
28801Jun2021
28801Jul2021
28701Aug2021
28801Sep2021

 

Sample Expecting output like below.

 

Applicant_No01-Nov-1901-Dec-1901-Jan-2001-Feb-2001-Mar-20
15757585656

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Your input has more than one applicant.  So use APPLICANT_NO in the BY statement instead of DATE.

proc SORT DATA=TEST OUT=TEST1;
  BY APPLICANT_NO DATE;
RUN;
proc transpose data=test1 out = test2;
  BY APPLICANT_NO ;
  ID DATE;
  VAR Days_Past_Due;
RUN;

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

What happens if you remove

 

id date;

 

from your code? Does it work then?

 

But basically, we don't really know what the desired output it. Can you show us what you want data set TEST2 to look like?

 

Also, you can't have a variable named APPLICANT NO and then refer to it as

 

VAR APPLICANT NO DPD;

 

because there can't be spaces in SAS variable name under normal operation. You could turn on an option that allows spaces in variable names, but you still can't use the above command as written. And you don't have a variable named DPD.

 

 

--
Paige Miller
saikiran_nemani
Obsidian | Level 7
I have updated it and please help me on this
PaigeMiller
Diamond | Level 26

It is an awful idea to have dates as variable names. Nor is there any easy way to get the dates into calendar order, they will most likely appear in alphabetical order.

 

How about using PROC REPORT rather than PROC TRANSPOSE? Assuming you are using numeric date values (are you?) then you can do this

 

proc report data=test1;
    columns applicant_no date,days_past_due;
    define applicant_no/group "Applicant #";
    define date/across "Date" order=internal format=monyy7.;
    define days_past_due/sum "Days Past Due";
run;

 

and your dates will be in calendar order, not alphabetical order.

--
Paige Miller
Tom
Super User Tom
Super User

Your input has more than one applicant.  So use APPLICANT_NO in the BY statement instead of DATE.

proc SORT DATA=TEST OUT=TEST1;
  BY APPLICANT_NO DATE;
RUN;
proc transpose data=test1 out = test2;
  BY APPLICANT_NO ;
  ID DATE;
  VAR Days_Past_Due;
RUN;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 549 views
  • 1 like
  • 4 in conversation