BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
CathyVI
Lapis Lazuli | Level 10

I have to following synthetic data similar to my data. I have millions of records so this is demo I created.

data test;

input Name $ sex $ weight height income;

cards;

Bob M 1 0 0

Mat M 0 1 0

Cat F 1 0 1

Dog F 1 0 0

Fred M 0 1 1

Sam M 0 0 1

Pat F 0 0 0

Jack M 1 1 1

;

run;

My goal is to identify when a row has more than 1 record within the variable weight, height and income.

For example the cat, fred and jack rows all have 1 record for each variable, how will I find these values. I want to identify row with more than 1 record separately from row with only 1 record.

So I want the count of cat, fred and jack separately and the count of bob, mat, dog, sam separately. I already identify the latter using this code;

 

data check;

set test;

if weight =1 or height =1 or income=1 then total_all=1;

else total_all=0;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

First identify which group a record belongs to and then you can determine later how to summarize them separately. You don't indicate how that would work so I'm guessing. It would have also been really helpful to see what you expect as output from this input. If my solution doesn't work, please post what you expect as output.

 

data want;
set test;

if sum(weight, height, income)>1 then group = "2";
else group = "1";

run;

proc freq data=want;
table group;
table group*name / list;
run;

@CathyVI wrote:

I have to following synthetic data similar to my data. I have millions of records so this is demo I created.

data test;

input Name $ sex $ weight height income;

cards;

Bob M 1 0 0

Mat M 0 1 0

Cat F 1 0 1

Dog F 1 0 0

Fred M 0 1 1

Sam M 0 0 1

Pat F 0 0 0

Jack M 1 1 1

;

run;

My goal is to identify when a row has more than 1 record within the variable weight, height and income.

For example the cat, fred and jack rows all have 1 record for each variable, how will I find these values. I want to identify row with more than 1 record separately from row with only 1 record.

So I want the count of cat, fred and jack separately and the count of bob, mat, dog, sam separately. I already identify the latter using this code;

 

data check;

set test;

if weight =1 or height =1 or income=1 then total_all=1;

else total_all=0;

run;


 

View solution in original post

1 REPLY 1
Reeza
Super User

First identify which group a record belongs to and then you can determine later how to summarize them separately. You don't indicate how that would work so I'm guessing. It would have also been really helpful to see what you expect as output from this input. If my solution doesn't work, please post what you expect as output.

 

data want;
set test;

if sum(weight, height, income)>1 then group = "2";
else group = "1";

run;

proc freq data=want;
table group;
table group*name / list;
run;

@CathyVI wrote:

I have to following synthetic data similar to my data. I have millions of records so this is demo I created.

data test;

input Name $ sex $ weight height income;

cards;

Bob M 1 0 0

Mat M 0 1 0

Cat F 1 0 1

Dog F 1 0 0

Fred M 0 1 1

Sam M 0 0 1

Pat F 0 0 0

Jack M 1 1 1

;

run;

My goal is to identify when a row has more than 1 record within the variable weight, height and income.

For example the cat, fred and jack rows all have 1 record for each variable, how will I find these values. I want to identify row with more than 1 record separately from row with only 1 record.

So I want the count of cat, fred and jack separately and the count of bob, mat, dog, sam separately. I already identify the latter using this code;

 

data check;

set test;

if weight =1 or height =1 or income=1 then total_all=1;

else total_all=0;

run;


 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 1210 views
  • 0 likes
  • 2 in conversation