BookmarkSubscribeRSS Feed
greg6363
Obsidian | Level 7
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.
1 REPLY 1
andreas_lds
Jade | Level 19
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]

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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