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

Dear SAS users,

Is there any Advance SAS user which can help me transpose some data.
Here is the example of starting table how it looks:

ACCOUNT_IDAPPLICATION_IDK_202001J_202001Z_202001K_202002J_202002Z_202002K_202003J_202003Z_202003
110123111213212223
220456141516242526
330789171819272829


And this is the results I want to have:

DATEACCOUNT_IDAPPLICATION_IDKJZ
202001110123
202001220456
202001330789
202002110111213
202002220141516
202002330171819
202003110212223
202003220242526
202003330272829



Thank you in advance brothers and sisters 🙂 

Kind regards,
Nikola

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

Please post data in usable form, those tables are nice to look at, but lack information about type and length of the variables.

This could be a solution:

data transposed;
	set have;
	
	length dateStr $ 6 variable $ 1 value 8 VarName $ 32;
	
	array vars K_202001--Z_202003;
	
	do i = 1 to dim(vars);
		VarName = vname(vars[i]);
		variable = first(VarName);
		dateStr = scan(VarName, 2, '_');
		value = vars[i];
		output;
	end;
	
	keep dateStr variable value Account_id Application_ID;
run;

proc sort data=work.transposed;
	by  dateStr Account_id Application_ID variable;
run;

proc transpose data=transposed out=want(drop=_name_);
	by dateStr Account_id Application_ID ;
	var value;
	id variable;
run; 

View solution in original post

1 REPLY 1
andreas_lds
Jade | Level 19

Please post data in usable form, those tables are nice to look at, but lack information about type and length of the variables.

This could be a solution:

data transposed;
	set have;
	
	length dateStr $ 6 variable $ 1 value 8 VarName $ 32;
	
	array vars K_202001--Z_202003;
	
	do i = 1 to dim(vars);
		VarName = vname(vars[i]);
		variable = first(VarName);
		dateStr = scan(VarName, 2, '_');
		value = vars[i];
		output;
	end;
	
	keep dateStr variable value Account_id Application_ID;
run;

proc sort data=work.transposed;
	by  dateStr Account_id Application_ID variable;
run;

proc transpose data=transposed out=want(drop=_name_);
	by dateStr Account_id Application_ID ;
	var value;
	id variable;
run; 

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 699 views
  • 1 like
  • 2 in conversation