BookmarkSubscribeRSS Feed
R_A_G_
Calcite | Level 5
Hello,

I've got another problem, I am using _N_ to have a count for my observations but for some reason it does not give me the correct count

Thanks
R.A.G
my Code:
data class (rename=(skills1-skills&num_skills=attributes1-attributes&num_skills));
set all_skills1;
array skills{&num_skills} skills1-skills&num_skills;
num=%eval(&num_skills);
if _type_=(2**num)-1 and sum(of skills1-skills&num_skills) ne .;

/*Lambda Intercept*/
num=1;
class=_n_;/****************************HOW???*************/
/*Lambda Main Effect*/
drop num _type_ _freq_ num;

run;
6 REPLIES 6
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
What is the value you are getting? Have you included this statement to verify with accuracy:

PUTLOG _ALL_;

Scott Barry
SBBWorks, Inc.
R_A_G_
Calcite | Level 5
the values I am getting starts from 66 and ends with 81, I have 4 variables with 16 observations.
Thanks
Tim_SAS
Barite | Level 11
_N_ counts the number of times the DATA step has iterated. It is not a count of observations.

See the doc about Automatic Variables.
NickR
Quartz | Level 8
_N_ is the count of observation read from the input dataset and not the observation written to output dataset.

In your case, you are subsetting the data and then assigning the value of _N_ to class variable. How about replacing the statement "class=_n_;" with "class+1;"
R_A_G_
Calcite | Level 5
thanks, that worked, but why?
thanks again
R.A.G
Ksharp
Super User
Because you have "if _type_=(2**num)-1 and sum(of skills1-skills&num_skills) ne .; ".


"if _type_=(2**num)-1 and sum(of skills1-skills&num_skills) ne .; " is actually ""if _type_=(2**num)-1 and sum(of skills1-skills&num_skills) ne . then output;"

That means only obs 66 - 81 suited this condition (i.e. _N_ = 66 - 81),only obs 66 - 81 will output dataset.


Ksharp

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 2168 views
  • 0 likes
  • 5 in conversation