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;
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.
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.
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;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.