BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ChuksManuel
Pyrite | Level 9

Hello programmers,

 

I believe this is a minor problem but i can't seem to get my head around it.

I obtained a count from an array and i am trying to use the where statement in the proc print to print only observations with a count of atleast 1 (count is atleast 1 if the patient weighs 230lb).

Here are my codes:

data four; set one;
array weight wt1-wt10;
count=0;
do over weight;
if weight gt 230 then count = count +1;
end;
proc print; var school wt1-wt10;
where wt1=1 and wt2=1 and wt3=1 and wt4=1 and wt5=1 and wt6=1 and wt7=1 and wt8=1 and wt9=1 and wt10=1;
run;

 

The first part of the code  ran but for some reasons, i can't get to print what i specified using proc print.

Any help will be appreciated.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

I obtained a count from an array and i am trying to use the where statement in the proc print to print only observations with a count of at least 1

If this is what you want why are you filtering on the WT variables and not the COUNT variable? I think this a logic issue. 

In the previous step tou're checking if WT1-WT10 is greater than 230 and I'm guessing that value will never be set to 1 because a weight of 1 isn't really possible.

 

I think this is what you want.

 

proc print data=four;
var school wt1-wt10;
where count>1;
run;

@ChuksManuel wrote:

Hello programmers,

 

I believe this is a minor problem but i can't seem to get my head around it.

I obtained a count from an array and i am trying to use the where statement in the proc print to print only observations with a count of atleast 1 (count is atleast 1 if the patient weighs 230lb).

Here are my codes:

data four; set one;
array weight wt1-wt10;
count=0;
do over weight;
if weight gt 230 then count = count +1;
end;
proc print; var school wt1-wt10;
where wt1=1 and wt2=1 and wt3=1 and wt4=1 and wt5=1 and wt6=1 and wt7=1 and wt8=1 and wt9=1 and wt10=1;
run;

 

The first part of the code  ran but for some reasons, i can't get to print what i specified using proc print.

Any help will be appreciated.

 

 


 

View solution in original post

3 REPLIES 3
ballardw
Super User

@ChuksManuel wrote:

Hello programmers,

 

I believe this is a minor problem but i can't seem to get my head around it.

I obtained a count from an array and i am trying to use the where statement in the proc print to print only observations with a count of atleast 1 (count is atleast 1 if the patient weighs 230lb).

Here are my codes:

data four; set one;
array weight wt1-wt10;
count=0;
do over weight;
if weight gt 230 then count = count +1;
end;
proc print; var school wt1-wt10;
where wt1=1 and wt2=1 and wt3=1 and wt4=1 and wt5=1 and wt6=1 and wt7=1 and wt8=1 and wt9=1 and wt10=1;
run;

 

The first part of the code  ran but for some reasons, i can't get to print what i specified using proc print.

Any help will be appreciated.

 

 


Show example data and the LOG when you run the proc print. I suspect you get a message :

NOTE: No observations were selected from data set

Since proc print does not do summaries then it is very likely that no single record meets all of those requirements.

Perhaps try OR instead of AND on your where statement. But without example data it is hard to see what you might actually want to do.

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

PeterClemmensen
Tourmaline | Level 20

Seems to me like this is what you want

 

proc print; var school wt1-wt10;
where count ge 1;
run;
Reeza
Super User

I obtained a count from an array and i am trying to use the where statement in the proc print to print only observations with a count of at least 1

If this is what you want why are you filtering on the WT variables and not the COUNT variable? I think this a logic issue. 

In the previous step tou're checking if WT1-WT10 is greater than 230 and I'm guessing that value will never be set to 1 because a weight of 1 isn't really possible.

 

I think this is what you want.

 

proc print data=four;
var school wt1-wt10;
where count>1;
run;

@ChuksManuel wrote:

Hello programmers,

 

I believe this is a minor problem but i can't seem to get my head around it.

I obtained a count from an array and i am trying to use the where statement in the proc print to print only observations with a count of atleast 1 (count is atleast 1 if the patient weighs 230lb).

Here are my codes:

data four; set one;
array weight wt1-wt10;
count=0;
do over weight;
if weight gt 230 then count = count +1;
end;
proc print; var school wt1-wt10;
where wt1=1 and wt2=1 and wt3=1 and wt4=1 and wt5=1 and wt6=1 and wt7=1 and wt8=1 and wt9=1 and wt10=1;
run;

 

The first part of the code  ran but for some reasons, i can't get to print what i specified using proc print.

Any help will be appreciated.

 

 


 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 1128 views
  • 0 likes
  • 4 in conversation