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]

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 741 views
  • 0 likes
  • 2 in conversation