BookmarkSubscribeRSS Feed
SMohanReddy
Obsidian | Level 7

proc sort data=delq_array;
by application app_month perf_month;
run;

data want;
set delq_array ;
by application app_month perf_month;
length string $60;
retain string;
string=compress(catx('',string,delq));
if last.application then do;
output;
call missing(string);
end;
run;

 

the aove program currently appends delq column data and outputs based on last.application. But i need to append '.' if there is missing performance based on perf_month column by application.

 

indata is attached. please help me on the logic

 

current output

Application App_month Perf_month string
1 1-Sep-15 1-Sep-17 000112345211000000000000
2 1-Sep-15 1-Jul-17 0001123452000000000
3 1-Sep-15 1-Jan-16

00

 

 

 

required output

Application App_month Perf_month string
1 1-Sep-15 1-Sep-17 000112345211000000000000
2 1-Sep-15 1-Jul-17 0001123452..0.00000000
3 1-Sep-15 1-Jan-16 .0.0
2 REPLIES 2
Astounding
PROC Star

One possibility:

 

data want;
set delq_array ;
by application app_month perf_month;
length string $60;
retain string;

if first.application then do;

   location=1;

   string = repeat('.', 59);

end;

else location + month_diff;
substr(string, location, 1) = put(delq, 1.);
if last.application;
run;

 

This assumes that DELQ is numeric.  If it is actually character with a length of $1, the program becomes simpler:

 

substr(string, location, 1) = delq;

MINX
Obsidian | Level 7

@Astounding Good approach. I simplifier your code and trim out all extra dots based on Month_Diff to make output as similar as post

 

data want;
	set delq_array ;
	by application app_month perf_month;
	length string $60;
	retain string;
	if first.application then string = repeat('.', 60);
	substr(string,Month_Diff,1) = strip(put(delq,best.));
	if last.application then do;
		string = substr(string,1,Month_Diff);
		output;
	end;
run;

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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