Help using Base SAS procedures

PROC TRANSPOSE or an array?

Reply
N/A
Posts: 1

PROC TRANSPOSE or an array?

I have a dataset with 2000+ observations. My primary key is a variable called
acct_num (account number). Within the observation, I have another
variable called asset_num (asset number). There is a one-to-many
relationship between acc_num and asset_num, meaning there can be
numerous asset numbers tied to a single (one) account number. My goal
is to get all the asset numbers tied to an account number within one
observation record. I would be creating asset_num1, asset_num2, etc.
to go across a single line for a single account number without
producing any duplicate account numbers to cover each individual asset
number. I tried using PROC TRANSPOSE with the var and id statements
but it didn't populate correctly. If I try setting up an array,
should I just use the two variables in question? Any assistance would
be greatly appreciated. Thanks.
Super Contributor
Posts: 264

Re: PROC TRANSPOSE or an array?

Using proc transpose requires the data to be sorted by acct_num.

[pre]data work.long;
input acct_num asset_num;
datalines;
1 1
1 2
1 3
1 4
2 5
2 6
2 7
2 8
2 9
3 10
3 11
;
run;

proc transpose data=work.long out=work.wide(drop=_name_) prefix=asset_num;
by acct_num;
var asset_num;
run;[/pre]
Ask a Question
Discussion stats
  • 1 reply
  • 156 views
  • 0 likes
  • 2 in conversation