I have a dataset
data LVG1;
set LVG;
by ln_no;
if comm_cd = 'CPBFOR' then CPBFOR=comm_dt ;
if comm_cd = 'SNTLVG' then SNTLVG=comm_dt ;
if comm_cd = 'UPBFOR' then UPBFOR=comm_dt ;
if ltr_id = 'RG901' then RG901=ltr_dt;
if ltr_id = 'RG902' then RG902=ltr_dt;
if ltr_id = 'RG903' then RG903=ltr_dt;
if ltr_id = 'CK007' then CK007=ltr_dt;
if ltr_id = 'CK009' then CK009=ltr_dt;
/*if SNTLVG >=d_LM_ACTIVATION_DT;*/
format CPBFOR SNTLVG UPBFOR RG901 RG902 RG903 CK007 CK009 mmddyy10.;
run;
I produced a proc transpose to capture the ln_no once and the individual comm_cd and ltr_id horizontally
proc transpose data= lvg1 out=lvg2
by ln_no;
var CPBFOR SNTLVG UPBFOR RG901 RG902 RG903 CK007 CK009 ;
run;
By default the proc transpose produces the ln_no and columns. Even though I have identified 8 vars, I only get 4 columns in my proc transpose. Why am only getting 4 columns when I have identified 8 variables (var)
Is this what you are looking to achieve?
DATA SINGLEOBS;
SET LVG1;
BY LN_NO;
RETAIN _:;
ARRAY VARS{*} CPBFOR SNTLVG UPBFOR RG901 RG902 RG903 CK007 CK009;
ARRAY _VARS{*} _CPBFOR _SNTLVG _UPBFOR _RG901 _RG902 _RG903 _CK007 _CK009;
DO I = 1 TO DIM(VARS);
IF FIRST.LN_NO THEN _VARS{I} = .;
IF VARS{I} THEN _VARS{I} = VARS{I};
END;
IF LAST.LN_NO THEN OUTPUT;
DROP _: I COMM_CD LTR_ID ;
FORMAT CPBFOR SNTLVG UPBFOR RG901 RG902 RG903 CK007 CK009 DATE9.;
RUN;
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.
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.