<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Variable length statement not working in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Variable-length-statement-not-working/m-p/758196#M239370</link>
    <description>Thank you! That worked</description>
    <pubDate>Thu, 29 Jul 2021 18:30:31 GMT</pubDate>
    <dc:creator>claremc</dc:creator>
    <dc:date>2021-07-29T18:30:31Z</dc:date>
    <item>
      <title>Variable length statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-length-statement-not-working/m-p/756038#M238630</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to cut down the length of my variables to save disc space and the usual length statement I use does not seem to be working.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data new_union;
length ss_other_specify $255. Manufacturer1 $50. Manufacturer2 $50. Vaccination_Code_Id1 $50. Vaccination_Code_Id2 $50.;
set union_combine;

/*Vax code format*/
if Vaccination_Code_Id1 in ("No vaccine administered", "Other", "Unknown vaccine or immune globulin") 
then Vaccination_Code_Id1 = ""; 
if Vaccination_Code_Id2 in ("No vaccine administered", "Other", "Unknown vaccine or immune globulin") 
then Vaccination_Code_Id2 = ""; 

/*Vax date format*/
Vaccination_Date1_d= mdy(substr(Vaccination_Date1,6,2), substr(Vaccination_Date1,9,2), substr(Vaccination_Date1,1,4)); 
Vaccination_Date2_d= mdy(substr(Vaccination_Date2,6,2), substr(Vaccination_Date2,9,2), substr(Vaccination_Date2,1,4)); 
drop Vaccination_Date1; 
drop Vaccination_Date2; 

format Vaccination_Date1_d mmddyy10. Vaccination_Date2_d mmddyy10.; 
run; 

data new_union; 
set new_union; 

rename Vaccination_Date1_d = Vaccination_Date1; 
rename Vaccination_Date2_d = Vaccination_Date2; 
format Vaccination_Date1 mmddyy10. Vaccination_Date2 mmddyy10.; 

/*Manufacturer reformat*/
Manufacturer1 = upcase(Manufacturer1); 
Manufacturer2 = upcase(Manufacturer2); 
if Manufacturer1 = "JOHNSON AND JOHNSON" then Manufacturer1 = "JANSSEN (JOHNSON AND JOHNSON)";
if Manufacturer1 = "PFIZER" then Manufacturer1 = "PFIZER/BIONTECH";
if Manufacturer2 = "JOHNSON AND JOHNSON" then Manufacturer2 = "JANSSEN (JOHNSON AND JOHNSON)";
if Manufacturer2 = "PFIZER" then Manufacturer2 = "PFIZER/BIONTECH";

/* if case_id in ("100734763","100748803") then Manufacturer2 = "" and Vaccination_Date2 = . and Vaccination_Code_Id2 = "";  */
/* if Manufacturer2 = "0" then Manufacturer2 = "";  */
run; 





&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After I run proc contents on the "new_union" dataset, the variable length is still $350, not $50 like I would like. I am running 2 separate data steps because I've had trouble with keeping them all in one when I use drop and rename.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2021 20:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-length-statement-not-working/m-p/756038#M238630</guid>
      <dc:creator>claremc</dc:creator>
      <dc:date>2021-07-22T20:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: Variable length statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-length-statement-not-working/m-p/756050#M238637</link>
      <description>&lt;P&gt;When you create a new dataset from existing dataset, then you should create new variable names. Length doesn't change on existing variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In your case,&amp;nbsp;Vaccination_Code_Id1 or 2 both are in&amp;nbsp;union_combine dataset. So try creating somewhat similar but different names in length statement as well as using them in code.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2021 21:10:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-length-statement-not-working/m-p/756050#M238637</guid>
      <dc:creator>Rydhm</dc:creator>
      <dc:date>2021-07-22T21:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: Variable length statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-length-statement-not-working/m-p/756060#M238638</link>
      <description>&lt;P&gt;Your program should have been effective at cutting down the length.&amp;nbsp; Are you sure you ran the PROC CONTENTS on the new data set, not the old?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2021 21:34:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-length-statement-not-working/m-p/756060#M238638</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-07-22T21:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: Variable length statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-length-statement-not-working/m-p/756062#M238639</link>
      <description>&lt;P&gt;I made some fake data like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data union_combine;
   length id 8 ss_other_specify $255. Vaccination_Date1 $10
          Manufacturer1 $350. Manufacturer2 $350. Vaccination_Code_Id1 $350. Vaccination_Code_Id2 $350.;
   retain Manufacturer1 "Big Pharma 1" Manufacturer2 "Big Pharma 2";
   do id=1 to 4;
      Vaccination_Code_Id1 =choosec(ID,"No vaccine administered", "Other", "Unknown vaccine or immune globulin"," "); 
      Vaccination_Code_Id2 =choosec(abs(5-ID),"No vaccine administered", "Other", "Unknown vaccine or immune globulin"," "); 
      Vaccination_Date1='----------';
      Vaccination_Date2='----------';
      substr(Vaccination_Date1,6,2)='07';
      substr(Vaccination_Date1,9,2)=put(ID,z2.);
      substr(Vaccination_Date1,1,4)='2021'; 
      substr(Vaccination_Date2,6,2)='07';
      substr(Vaccination_Date2,9,2)=put(ID+14,z2.);
      substr(Vaccination_Date2,1,4)='2021'; 
      Manufacturer1 = choosec(ID,"JOHNSON AND JOHNSON","PFIZER","JOHNSON AND JOHNSON","PFIZER");
      Manufacturer2 = choosec(ID,"PFIZER","JOHNSON AND JOHNSON","PFIZER","JOHNSON AND JOHNSON");
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I ran this single data step that did all the conversions you were doing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new_union;
   length ss_other_specify $255. Manufacturer1 $50. Manufacturer2 $50. Vaccination_Code_Id1 $50. Vaccination_Code_Id2 $50.;
   set union_combine (rename=(Vaccination_Date1 = _dt1 Vaccination_Date2 = _dt2)); 
   /*Vax code format*/
   if Vaccination_Code_Id1 in ("No vaccine administered", "Other", "Unknown vaccine or immune globulin") 
   then Vaccination_Code_Id1 = ""; 
   if Vaccination_Code_Id2 in ("No vaccine administered", "Other", "Unknown vaccine or immune globulin") 
   then Vaccination_Code_Id2 = ""; 

   /*Vax date format*/
   Vaccination_Date1= mdy(substr(_dt1,6,2), substr(_dt1,9,2), substr(_dt1,1,4)); 
   Vaccination_Date2= mdy(substr(_dt2,6,2), substr(_dt2,9,2), substr(_dt2,1,4)); 
   Manufacturer1 = upcase(Manufacturer1); 
   Manufacturer2 = upcase(Manufacturer2); 
   if Manufacturer1 = "JOHNSON AND JOHNSON" then Manufacturer1 = "JANSSEN (JOHNSON AND JOHNSON)";
   if Manufacturer1 = "PFIZER" then Manufacturer1 = "PFIZER/BIONTECH";
   if Manufacturer2 = "JOHNSON AND JOHNSON" then Manufacturer2 = "JANSSEN (JOHNSON AND JOHNSON)";
   if Manufacturer2 = "PFIZER" then Manufacturer2 = "PFIZER/BIONTECH";
   drop _:; 
   format Vaccination_Date1 mmddyy10. Vaccination_Date2 mmddyy10.; 
run; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the variable sizes I changed to $50 worked just fine:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=new_union; 
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Contents: Variables" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="c b header" colspan="5" scope="colgroup"&gt;Alphabetic List of Variables and Attributes&lt;/TH&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;#&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;Variable&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;Type&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Len&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;Format&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="l data"&gt;Manufacturer1&lt;/TD&gt;
&lt;TD class="l data"&gt;Char&lt;/TD&gt;
&lt;TD class="r data"&gt;50&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="l data"&gt;Manufacturer2&lt;/TD&gt;
&lt;TD class="l data"&gt;Char&lt;/TD&gt;
&lt;TD class="r data"&gt;50&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="l data"&gt;Vaccination_Code_Id1&lt;/TD&gt;
&lt;TD class="l data"&gt;Char&lt;/TD&gt;
&lt;TD class="r data"&gt;50&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="l data"&gt;Vaccination_Code_Id2&lt;/TD&gt;
&lt;TD class="l data"&gt;Char&lt;/TD&gt;
&lt;TD class="r data"&gt;50&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;7&lt;/TH&gt;
&lt;TD class="l data"&gt;Vaccination_Date1&lt;/TD&gt;
&lt;TD class="l data"&gt;Num&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;TD class="l data"&gt;MMDDYY10.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;8&lt;/TH&gt;
&lt;TD class="l data"&gt;Vaccination_Date2&lt;/TD&gt;
&lt;TD class="l data"&gt;Num&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;TD class="l data"&gt;MMDDYY10.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;6&lt;/TH&gt;
&lt;TD class="l data"&gt;id&lt;/TD&gt;
&lt;TD class="l data"&gt;Num&lt;/TD&gt;
&lt;TD class="r data"&gt;8&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="l data"&gt;ss_other_specify&lt;/TD&gt;
&lt;TD class="l data"&gt;Char&lt;/TD&gt;
&lt;TD class="r data"&gt;255&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you share your results?&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2021 21:39:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-length-statement-not-working/m-p/756062#M238639</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2021-07-22T21:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: Variable length statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-length-statement-not-working/m-p/756081#M238657</link>
      <description>&lt;P&gt;For which specific variable? You have 4 variables where you might be setting the length to 50.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can avoid all of the character to numeric conversion messages you get from using this code:&lt;/P&gt;
&lt;PRE&gt;/*Vax date format*/
Vaccination_Date1_d= mdy(substr(Vaccination_Date1,6,2), substr(Vaccination_Date1,9,2), substr(Vaccination_Date1,1,4)); 
Vaccination_Date2_d= mdy(substr(Vaccination_Date2,6,2), substr(Vaccination_Date2,9,2), substr(Vaccination_Date2,1,4)); &lt;/PRE&gt;
&lt;P&gt;by using the proper INFORMAT on the entire string.&lt;/P&gt;
&lt;PRE&gt;Data example;
   x='21020715';
   y=input(x,yymmdd8.);
   format y mmddyy10.;
run;&lt;/PRE&gt;
&lt;P&gt;Or if your Vaccination_date variables are simple numbers convert to string and use informat&lt;/P&gt;
&lt;PRE&gt;Data example2;
   x=21020715;
   y=input(put(x,f8.),yymmdd8.);
   format y mmddyy10.;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2021 22:13:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-length-statement-not-working/m-p/756081#M238657</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-22T22:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: Variable length statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-length-statement-not-working/m-p/756170#M238698</link>
      <description>&lt;PRE&gt;data have;
set sashelp.class;
run;

proc sql;
alter table have
modify sex char(20),name char(10);
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Jul 2021 12:35:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-length-statement-not-working/m-p/756170#M238698</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-07-23T12:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: Variable length statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-length-statement-not-working/m-p/758196#M239370</link>
      <description>Thank you! That worked</description>
      <pubDate>Thu, 29 Jul 2021 18:30:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-length-statement-not-working/m-p/758196#M239370</guid>
      <dc:creator>claremc</dc:creator>
      <dc:date>2021-07-29T18:30:31Z</dc:date>
    </item>
  </channel>
</rss>

