Hello There,
Will anyone please help me to get the solution for this problem,
From sashelp.class data set I want 5th 10th and 15th observation (or observations in multiple of 5) in output and in Log window it should read only the given output.
Look up the MOD() function.
@vishalrajpoot3 wrote:
Hello There,
Will anyone please help me to get the solution for this problem,
From sashelp.class data set I want 5th 10th and 15th observation (or observations in multiple of 5) in output and in Log window it should read only the given output.
I think using mod() will give me remainder. Could you please help to advise how we can use to get the every 5th observation in output.
@vishalrajpoot3 wrote:
I think using mod() will give me remainder. Could you please help to advise how we can use to get the every 5th observation in output.
Yes it does. And if you divide by 5 what's the remainder?
it will give 0(zero), but this was not the question.
@vishalrajpoot3 wrote:
I think using mod() will give me remainder. Could you please help to advise how we can use to get the every 5th observation in output.
data want; set sashelp.class; if mod(_n_,5)=0; line=_n_; run;
Line to show which line the record comes from.
data want;
do _n_=5 to nobs by 5;
set sashelp.class point=_n_ nobs=nobs;
put _all_;
output;
end;
stop;
run;
@Reeza and @novinosrin both have provided you with answers. Welcome to SAS forum as it seems you are new.
First off, it seems you are unable to apply the mod function with a condition. This is where quantitative skills are imperative to be successful in any programming. Try to think through why Reeza suggested mod, if mod results in zero for every fifth obs and not in zero for others. What do you have to do next?
With some effort, you will get the hang of it, but you will have to do that thinking by yourself since the directions have been provided
Thanks Everyone.
Yes, I am new in any of the programming, SAS is the very first platform to write code.
Let me try that answer first.
This is a contrived problem to try and learn with. I wouldn't recommend starting here...I've only seen this type of question in practice tests or interview questions and it's rarely used in practice.
If you're trying to learn the first SAS Programming e-course is free, as well as the tutorials on UCLA which are quite helpful.
Thank you everyone for providing you valuable inputs to solve the subjected problem.
Here is one more solution -->
data abc;
num + 5;
set sashelp.class nobs = k point = num;
if num ge k then stop;
output;
run;
Note - This code will allow pointer to jump to every 5th observation and will save the processing time in case of huge data set.
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!
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.