DATA Step, Macro, Functions and more

proc transpose issues

Reply
Contributor
Posts: 59

proc transpose issues

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)

Super Contributor
Posts: 297

Re: proc transpose issues

Posted in reply to omega1983

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;

Ask a Question
Discussion stats
  • 1 reply
  • 150 views
  • 0 likes
  • 2 in conversation