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

Hi,

 

I'm looking for a solution to transform multiple observations into a single observation. I've included the current state and future state images below. (Note: all values are in character format)

 

LNDR_FMLY_IDQTR_IDINCMASTSLIAB
ARBRT2015Q1130,967  
ARBRT2015Q1 2,742,733 
ARBRT2015Q1  1,892,937
JPMOR2015Q2100,267  

 

LNDR_FMLY_IDQTR_IDINCMASTSLIAB
ARBRT2015Q1130,9672,742,7331,892,937
JPMOR2015Q2100,267  
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data have;
input (LNDR_FMLY_ID	QTR_ID	INCM	ASTS	LIAB) (:$25.);
cards;
ARBRT	2015Q1	130,967	 	. .
ARBRT	2015Q1	 .	2,742,733	. 
ARBRT	2015Q1	 	. . 	1,892,937
JPMOR	2015Q2	100,267	 . .	 
;
data want;
update have(obs=0) have;
by LNDR_FMLY_ID QTR_ID;
run;

View solution in original post

10 REPLIES 10
novinosrin
Tourmaline | Level 20
data have;
input (LNDR_FMLY_ID	QTR_ID	INCM	ASTS	LIAB) (:$25.);
cards;
ARBRT	2015Q1	130,967	 	. .
ARBRT	2015Q1	 .	2,742,733	. 
ARBRT	2015Q1	 	. . 	1,892,937
JPMOR	2015Q2	100,267	 . .	 
;
data want;
update have(obs=0) have;
by LNDR_FMLY_ID QTR_ID;
run;
aakash93
Calcite | Level 5

Similar to my question to Ballardw, what if I add an additional variable such as Y/N indicator variable that is character type? Adding a character type variable results in a null value.

novinosrin
Tourmaline | Level 20

Please provide your modified sample

aakash93
Calcite | Level 5
LNDR_FMLY_IDQTR_IDINCMASTSLIABBANK_IND (character)
ARBRT2015Q1   Y
ARBRT2015Q1130,967   
ARBRT2015Q1 2,742,733  
ARBRT2015Q1  1,892,937 
JPMOR2015Q2100,267   
      
      
      
      
LNDR_FMLY_IDQTR_IDINCMASTSLIABBANK_IND (character)
ARBRT2015Q1130,9672,742,7331,892,937Y
JPMOR2015Q2100,267   
      
aakash93
Calcite | Level 5

Also forgot to mention this is after I converted INCM ASTS and LIAB to numeric.

novinosrin
Tourmaline | Level 20

Here is my test and results:

 

data have;
infile cards truncover;
input (LNDR_FMLY_ID	QTR_ID	INCM	ASTS	LIAB	BANK_IND) (:$25.);
cards;
ARBRT	2015Q1	. .  .	 	 	Y
ARBRT	2015Q1	130,967	 . . .	 	 
ARBRT	2015Q1	 .	2,742,733	. . 	 
ARBRT	2015Q1	 .  .	 	1,892,937	. 
JPMOR	2015Q2	100,267	 .  .  .	 	 
;

data want;
update have(obs=0) have;
by LNDR_FMLY_ID QTR_ID;
run;
proc print noobs;
run;

SAS Output

LNDR_FMLY_ID QTR_ID INCM ASTS LIAB BANK_IND
ARBRT2015Q1130,9672,742,7331,892,937Y
JPMOR2015Q2100,267   
novinosrin
Tourmaline | Level 20

After reading your conversion message, yet another test:

 

data have;
infile cards truncover;
input LNDR_FMLY_ID :$20.	QTR_ID :$20.	INCM	ASTS	LIAB	BANK_IND :$2.;
cards;
ARBRT	2015Q1	. .  .	 	 	Y
ARBRT	2015Q1	130967	 . . .	 	 
ARBRT	2015Q1	 .	2742733	. . 	 
ARBRT	2015Q1	 .  .	 	1892937	. 
JPMOR	2015Q2	100267	 .  .  .	 	 
;

data want;
update have(obs=0) have;
by LNDR_FMLY_ID QTR_ID;
run;
proc print noobs;
run;

SAS Output

LNDR_FMLY_ID QTR_ID INCM ASTS LIAB BANK_IND
ARBRT2015Q113096727427331892937Y
JPMOR2015Q2100267.. 
ballardw
Super User

If the variables INCM ASTS and LIAB are numeric and there are no duplicates for combinations of LNDR_FMLY_ID and QTR_ID then

 

Proc summary data=have nway;

   class LNDR_FMLY_ID QTR_ID ;

   var INCM ASTS LIAB ;

   output out=want (drop= _type_ _freq_) max=;

run;

 

would be one way.

aakash93
Calcite | Level 5

This solution works as well. What if I add an additional variable such as Y/N indicator that is character type?

ballardw
Super User

@aakash93 wrote:

This solution works as well. What if I add an additional variable such as Y/N indicator that is character type?


Example input and output. Depends on if the indicator changes between your original records for the same group or not. If it does a rule for what the final should be.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 10 replies
  • 1032 views
  • 0 likes
  • 3 in conversation