BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
lu_king
Obsidian | Level 7
Hi everybody! I would like to create an additional variable that is the average of my duplicate target levels with my main target levels. I don’t want the 0’s to average with another sample though. For example on May 6, located at EU, there are two levels for the N.GIII target…I’d like to average those together, but on May 20, located at HU, the duplicate sample is a non-zero, I don’t want to average that value, with the zero in the main sample. Any guidance would be appreciated!
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Why attach a file to share a hand full of values?

date sample tylocation target levels
6-May main EU N.GIII 32
6-May dupe EU N.GIII 456
7-May main PR CII 645465
7-May dupe PR CII 0
20-May main HU AGI 0
20-May dupe HU AGI 64875833

Can you code the rules that explain which values you want to ignore?  Use them to make a NEW variable (so your original data is not lost) which has MISSING values where you don't want to use the original value.

data for_analysis;
  set have;
  new_var = levels;
  if levels=0 then new_var=.;
run;

Now you can take the MEAN() of your new variable.

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Turn the zeros into missing values.

 

Also, most of us refuse to download Excel (or Microsoft Office) files as they can be a security threat. The proper way to include data is as text in working SAS data step code (examples and instructions)

--
Paige Miller
Tom
Super User Tom
Super User

Why attach a file to share a hand full of values?

date sample tylocation target levels
6-May main EU N.GIII 32
6-May dupe EU N.GIII 456
7-May main PR CII 645465
7-May dupe PR CII 0
20-May main HU AGI 0
20-May dupe HU AGI 64875833

Can you code the rules that explain which values you want to ignore?  Use them to make a NEW variable (so your original data is not lost) which has MISSING values where you don't want to use the original value.

data for_analysis;
  set have;
  new_var = levels;
  if levels=0 then new_var=.;
run;

Now you can take the MEAN() of your new variable.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 520 views
  • 0 likes
  • 3 in conversation