BookmarkSubscribeRSS Feed
omega1983
Calcite | Level 5

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)

1 REPLY 1
Scott_Mitchell
Quartz | Level 8

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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1216 views
  • 0 likes
  • 2 in conversation