How to make my output to read as yes or no?

Viewed 96

I want to display my data as either yes or no in the output for initaltesting, site visit, and follow up, how would I do that? There are numeric values for this on the data set but want character responses of "y" or "n"

    PROC FORMAT;

    VALUE SiteVisitfmt  1 = 'yes' 
                0 = 'no';

    VALUE InitialTestingfmt 1 = 'yes'
                    2 = 'no';

    VALUE TestEventfmt 1 = 'One Event '
               2 = 'Two Events'
               3 = 'Three Events'
               4 = 'Four Events'
               5 = 'Five Events';

    VALUE FollowUpfmt 1 = 'yes'
              0 = 'no';

    FORMAT SiteVisit SiteVisitfmt. InitialTesting InitialTestingfmt. TestEvent TestEventfmt. 
    FollowUp FollowUpfmt.;

   RUN;
   data PMdataedits;
   set PMdata (rename = (Number_of_Days_from_Onset_to_Sit   =SiteVisit
                      Number_of_Days_between_Onset_and   = InitialTesting
                      Number_of_Test_Events_in_IRIS      = TestEvent
                      Number_of_Days_between_Test_1_an   = FollowUp));
  drop SPA;
  attrib date1 format=date9.;
  date1=input(date,mmddyy10.);
  NewSiteVisit = put(SiteVisit, 8.);

  NewInitialTesting = put(InitialTesting, 8.);

  NewFollowUp = put(FollowUp, 8.);

 NewSiteVisit=;
 if (NewSiteVisit=<1) THEN NewSiteVisit= '1';
 if (NewSiteVisit>1) THEN NewSiteVist= '0';

NewInitialTesting=;
if (NewInitialTesting<=2) THEN NewInitialTesting= '1';
if (NewInitialTesting>2) THEN NewInitialTesting='0';
1 Answers

This statement:

FORMAT SiteVisit SiteVisitfmt. InitialTesting InitialTestingfmt. TestEvent TestEventfmt. 
FollowUp FollowUpfmt.;

Needs to be on the data step (sometime after data PMdataedits; but before the run; that you don't show), not in the proc format. That's the statement that assigns the format to a variable; each dataset (which is defined by a data step) has its own, unique set of variables that can be the same name as other datasets but have different contents and formats.

Also note that you don't have to name the formats after the variables, and don't need three different yes/no formats. You could have done:

proc format;
  format ynf
   '1'='yes'
   '0'='no'
  ;
run;

And then used

format sitevisit initialtesting followup ynf.;

And that would have covered all three of them with one format. But what you did is legal, it's just more typing than you need!

Related