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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

3 REPLIES 3
Tom
Super User Tom
Super User

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.

tmcrouse
Calcite | Level 5

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;

Tom
Super User Tom
Super User

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 747 views
  • 0 likes
  • 2 in conversation