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

I need to double check the answers to the question of homelessness does not change at different dates.  In the below example I would like to see if the response variables in one record are the same across different dates. These answers supposedly do not change, but want to double check

 

ChildID        Homelessnow        Homelessrecently     Date

123             Yes                                no                       10/12/12

123             Yes                               Yes                       2/1/13

123             No                                 no                        4/1/13

456             Yes                              Yes                      11/12/12

456              No                                no                         4/2/13

456             Yes                              Yes                     6/1/13

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@malena wrote:

I need to double check the answers to the question of homelessness does not change at different dates.  In the below example I would like to see if the response variables in one record are the same across different dates. These answers supposedly do not change, but want to double check

 

ChildID        Homelessnow        Homelessrecently     Date

123             Yes                                no                       10/12/12

123             Yes                               Yes                       2/1/13

123             No                                 no                        4/1/13

456             Yes                              Yes                      11/12/12

456              No                                no                         4/2/13

456             Yes                              Yes                     6/1/13


An example of why coding text "yes" "no" is inefficient. If the values were 1 for 'Yes' and 0 for 'No' as numeric values then the RANGE function would tell if any of the values were different, since range is Largest value - Smallest value. If they are all the same then the Range is 0, and if any change then you would have a range of 1.

 

Here's an example of creating 1/0 coded variables and then using proc means to look at the summary. Note how to provide example data as a data step so code can be tested. Also I added an id value that the two homeless variables didn't change to show the result.

Proc Report or Tabulate could do so as well.

proc format library=work;
invalue myyesno (upcase)
'YES' = 1
'NO'  = 0
other = .
;
/* making numeric values from the text*/
data example;
input ChildID $       Homelessnow $       Homelessrecently  $   Date :anydtdte.;
format date date9.;
HNnum =input(Homelessnow, myyesno.);
HRnum = input (Homelessrecently, myyesno.);
datalines;
123             Yes                                no                       10/12/12
123             Yes                               Yes                       2/1/13
123             No                                 no                        4/1/13
456             Yes                              Yes                      11/12/12
456              No                                no                         4/2/13
456             Yes                              Yes                     6/1/13
457             Yes                              Yes                      11/12/12
457             Yes                              Yes                         4/2/13
457             Yes                              Yes                     6/1/13
;


proc means data=example range;
   class childid;
   var hnnum hrnum;
run;

Other reasons to code yes/no or True/false values as numeric 1/0. You can sum the variable and get the count of "Yes" easily. The Mean of a 1/0 coded variable is the percent of "Yes" results.

Or if you have multiple variables in a record that you need to know

    how many were "Yes" : Sum

    All the same: Range 

    Any were 'Yes': Max

    Any were 'No': Min

    how many were 'No':  N of variables - Sum of variables

  

ALL of these multivariable questions are one line of code. If you work with Yes/No text (and not consistently spelled in your example) you get to right something that either 1) creates numeric values and uses the summary functions or 2) LOTS of ugly if/then/else counting code.

View solution in original post

2 REPLIES 2
RichardDeVen
Barite | Level 11

Can you clarify the question by showing which of the data is correct and which is deemed incorrect by double checking ?

ballardw
Super User

@malena wrote:

I need to double check the answers to the question of homelessness does not change at different dates.  In the below example I would like to see if the response variables in one record are the same across different dates. These answers supposedly do not change, but want to double check

 

ChildID        Homelessnow        Homelessrecently     Date

123             Yes                                no                       10/12/12

123             Yes                               Yes                       2/1/13

123             No                                 no                        4/1/13

456             Yes                              Yes                      11/12/12

456              No                                no                         4/2/13

456             Yes                              Yes                     6/1/13


An example of why coding text "yes" "no" is inefficient. If the values were 1 for 'Yes' and 0 for 'No' as numeric values then the RANGE function would tell if any of the values were different, since range is Largest value - Smallest value. If they are all the same then the Range is 0, and if any change then you would have a range of 1.

 

Here's an example of creating 1/0 coded variables and then using proc means to look at the summary. Note how to provide example data as a data step so code can be tested. Also I added an id value that the two homeless variables didn't change to show the result.

Proc Report or Tabulate could do so as well.

proc format library=work;
invalue myyesno (upcase)
'YES' = 1
'NO'  = 0
other = .
;
/* making numeric values from the text*/
data example;
input ChildID $       Homelessnow $       Homelessrecently  $   Date :anydtdte.;
format date date9.;
HNnum =input(Homelessnow, myyesno.);
HRnum = input (Homelessrecently, myyesno.);
datalines;
123             Yes                                no                       10/12/12
123             Yes                               Yes                       2/1/13
123             No                                 no                        4/1/13
456             Yes                              Yes                      11/12/12
456              No                                no                         4/2/13
456             Yes                              Yes                     6/1/13
457             Yes                              Yes                      11/12/12
457             Yes                              Yes                         4/2/13
457             Yes                              Yes                     6/1/13
;


proc means data=example range;
   class childid;
   var hnnum hrnum;
run;

Other reasons to code yes/no or True/false values as numeric 1/0. You can sum the variable and get the count of "Yes" easily. The Mean of a 1/0 coded variable is the percent of "Yes" results.

Or if you have multiple variables in a record that you need to know

    how many were "Yes" : Sum

    All the same: Range 

    Any were 'Yes': Max

    Any were 'No': Min

    how many were 'No':  N of variables - Sum of variables

  

ALL of these multivariable questions are one line of code. If you work with Yes/No text (and not consistently spelled in your example) you get to right something that either 1) creates numeric values and uses the summary functions or 2) LOTS of ugly if/then/else counting code.

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
  • 2 replies
  • 1065 views
  • 0 likes
  • 3 in conversation