BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Luke1234
Calcite | Level 5

I'm looking to take the first row of each group in a table and create an additional row that has the value from the first column (prod) in the second column (comp). Basically, this is an unbundling of a product, where a product ID has components attached to it, but the actual product ID itself should also be considered part of the bundle (one of the components) when joining to other tables.

Have:

ProdComp
x1
x2
x3
y1
y2

 

Want:

ProdComp
xx
x1
x2
x3
yy
y1
y2
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use BY processing combined with an explicit output statement. You may have to tweak this if you want to maintain the order, and if you want to include character and numeric values in a single column - it will have to be a character variable.

 

data want;
set have;
by prod;

if first.prod then do;
output;
comp=prod;
output;
end;
else output;
run;

View solution in original post

1 REPLY 1
Reeza
Super User

Use BY processing combined with an explicit output statement. You may have to tweak this if you want to maintain the order, and if you want to include character and numeric values in a single column - it will have to be a character variable.

 

data want;
set have;
by prod;

if first.prod then do;
output;
comp=prod;
output;
end;
else output;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 4735 views
  • 3 likes
  • 2 in conversation