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-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 859 views
  • 0 likes
  • 3 in conversation