Help using Base SAS procedures

format length problem

Accepted Solution Solved
Reply
Contributor
Posts: 69
Accepted Solution

format length problem

I am trying to format a length because the main items are maximum of 10 chararacter lengths and I have a few that are longer. Here is an example of my code and not sure how to state the length. the format=$11. does not work.

data cardiac.tinmin_restudy2;

     if _N_=1 then do;

     declare hash h(dataset: "cardiac.tinmin_restudy(where=(prov_tin_min_restudy=1) rename=(fst_srvc_dt=min_study_start_date))");

     h.defineKey('mbr_sys_id');

     h.defineData('min_study_start_date');

     h.defineDone();

     end;

     set cardiac.tinmin_restudy;

     rc=h.find();

     if rc=0 then do;

     if (1 LE fst_srvc_dt - min_study_start_date LE 90) and (nat_tee=1 or nat_tte=1 or nat_secho=1) then do;

          if nat_tee=1 and office_clinic = 1 then sub_table="OFCMINTEE";

          else if nat_tte=1 and office_clinic = 1 then sub_table="OFCMINTTE";

          else if nat_secho=1 and office_clinic = 1 then sub_table="OFCMINSECHO" FORMAT=$11. ;

          else if nat_tee=1 and office_clinic = 1 then sub_table="IPMINTEE";

          else if nat_tte=1 and inpatient_facility = 1 then sub_table="IPMINTTE";

          else if nat_secho=1 and inpatient_facility = 1 then sub_table="IPMINSECHO";

          else if nat_tee=1 and inpatient_facility = 1 then sub_table="OPMINTEE";

          else if nat_tte=1 and inpatient_facility = 1 then sub_table="OPMINTTE";

          else if nat_secho=1 and outpatient_facility = 1 then sub_table="OPMINSECHO";

          output;

          end;

     end;

     drop rc min_study_start_date;

run;


Accepted Solutions
Solution
‎09-10-2013 12:49 PM
Super User
Super User
Posts: 6,500

Re: format length problem

To define the length of a character variable use a LENGTH or ATTRIB statement.  A format is just a specification of how to display a value, not how to store it.

If the variable is already in your incoming dataset then you will need place the LENGTH statement before the SET statement to change the definition of the variable.

View solution in original post


All Replies
Solution
‎09-10-2013 12:49 PM
Super User
Super User
Posts: 6,500

Re: format length problem

To define the length of a character variable use a LENGTH or ATTRIB statement.  A format is just a specification of how to display a value, not how to store it.

If the variable is already in your incoming dataset then you will need place the LENGTH statement before the SET statement to change the definition of the variable.

Contributor
Posts: 69

Re: format length problem

It looks like I would do this:

data cardiac.tinmin_restudy2;

     if _N_=1 then do;

     declare hash h(dataset: "cardiac.tinmin_restudy(where=(prov_tin_min_restudy=1) rename=(fst_srvc_dt=min_study_start_date))");

     h.defineKey('mbr_sys_id');

     h.defineData('min_study_start_date');

     h.defineDone();

     end;

length sub_table $15;  *********15 just to be safe****

     set cardiac.tinmin_restudy;

     rc=h.find();

     if rc=0 then do;

     if (1 LE fst_srvc_dt - min_study_start_date LE 90) and (nat_tee=1 or nat_tte=1 or nat_secho=1) then do;

          if nat_tee=1 and office_clinic = 1 then sub_table="OFCMINTEE";

          else if nat_tte=1 and office_clinic = 1 then sub_table="OFCMINTTE";

          else if nat_secho=1 and office_clinic = 1 then sub_table="OFCMINSECHO" FORMAT=$11. ;

          else if nat_tee=1 and office_clinic = 1 then sub_table="IPMINTEE";

          else if nat_tte=1 and inpatient_facility = 1 then sub_table="IPMINTTE";

          else if nat_secho=1 and inpatient_facility = 1 then sub_table="IPMINSECHO";

          else if nat_tee=1 and inpatient_facility = 1 then sub_table="OPMINTEE";

          else if nat_tte=1 and inpatient_facility = 1 then sub_table="OPMINTTE";

          else if nat_secho=1 and outpatient_facility = 1 then sub_table="OPMINSECHO";

          output;

          end;

     end;

     drop rc min_study_start_date;

run;

Super User
Super User
Posts: 6,500

Re: format length problem

You need to remove the spurious "FORMAT=$11." from one of the assignment statements in the middle of the series of if/else if statements.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 179 views
  • 0 likes
  • 2 in conversation