BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
stellapersis7
Obsidian | Level 7

I have a dataset like this. how do i pick just few items like only  V3000 and 225 and corresponding L_O_S and put it in different table.

N obsA_DL_O_S
1V300023

2

2254
3v300165
478564
5v24067

 

1 ACCEPTED SOLUTION
4 REPLIES 4
stellapersis7
Obsidian | Level 7

Thanks a lot. I have a this kind of dataset where I need to average the L_O_S variables and pick V3000 and 225 against the corresponding average L_O_S? can anyone please help with it?

N obsA_DL_O_S
1V300023

2

2254
3v300165
478564
5v24067
Tom
Super User Tom
Super User

@stellapersis7 wrote:

Thanks a lot. I have a this kind of dataset where I need to average the L_O_S variables and pick V3000 and 225 against the corresponding average L_O_S? can anyone please help with it?

N obs A_D L_O_S
1 V3000 23

2

225 4
3 v3001 65
4 7856 4
5 v240 67

Your description is not very precise.  What does "pick" mean?  What does "against" mean?

What is the answer you want for the data you showed?  How did you get to that answer?

 

If you want to find averages use PROC MEANS

proc means data=have;
  class a_d ;
  var l_o_s;
run;

or perhaps the MEAN() aggregate function in PROC SQL.

proc sql;
create table want as
  select a_d,mean(l_o_s) as mean_los 
  from have
  group by a_d
;
quit;
SubbuPaz
SAS Employee

Try this code if you would like to 'pick' a subset of a_d values and get mean_los 'against' each n_obs | a_d:

Note that in your sample data the 'a_d' column is unique. May be your actual data set has multiple observations for each 'a_d' - for average computation. 

 

data have;
input n_obs a_d $ l_o_s;
datalines;
1 V3000 23
2 225 4
3 v3001 65
4 7856 4
5 v240 67
;

proc sql;
create table want as
select a.n_obs, a.a_d, b.mean_los
from
(select n_obs, a_d, l_o_s from have
where a_d in ("V3000","225"))a
left join
(select a_d,mean(l_o_s) as mean_los
from have
group by a_d)b
on a.a_d = b.a_d
;
quit;

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 622 views
  • 2 likes
  • 4 in conversation