<?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: How do I change the format and designate length for two conditions? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-the-format-and-designate-length-for-two/m-p/536074#M147275</link>
    <description>&lt;P&gt;I'd be adding leading zero's to all of your ID's (using format z5. only) so sorting behaves as you'd likely would want it - but here you go:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id ;
  datalines;
00001
00002
00003
00099
00100
2000
2001
2002
2019
2020
;
run;

proc format;
  value conv_id (default=5)
    0-100  = [z5.]
    other = [f5.]
  ;
quit;


data have(drop=id_orig);
  set have(rename=(id=id_orig));
  length id $5;
  id=put(id_orig,conv_id. -l);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 15 Feb 2019 22:02:32 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2019-02-15T22:02:32Z</dc:date>
    <item>
      <title>How do I change the format and designate length for two conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-the-format-and-designate-length-for-two/m-p/536071#M147274</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a ID column is currently numeric, and I would like to change it to character. I have a hundred ID numbers 1-100 needs to be 5 numbers beginning with zero, e.g. 00001, 00002, 00003,.....,00099, 00100. Then another twenty ID numbers just need to be 4 numbers, beginning with two, e.g. 2000, 2001, 2002, 2003, ......2020.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&lt;/P&gt;&lt;P&gt;00001&lt;/P&gt;&lt;P&gt;00002&lt;/P&gt;&lt;P&gt;00003&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;00099&lt;/P&gt;&lt;P&gt;00100&lt;/P&gt;&lt;P&gt;2000&lt;/P&gt;&lt;P&gt;2001&lt;/P&gt;&lt;P&gt;2002&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2019&lt;/P&gt;&lt;P&gt;2020&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I change the format and designate the length for these two conditions? Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2019 21:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-the-format-and-designate-length-for-two/m-p/536071#M147274</guid>
      <dc:creator>Denali</dc:creator>
      <dc:date>2019-02-15T21:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I change the format and designate length for two conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-the-format-and-designate-length-for-two/m-p/536074#M147275</link>
      <description>&lt;P&gt;I'd be adding leading zero's to all of your ID's (using format z5. only) so sorting behaves as you'd likely would want it - but here you go:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id ;
  datalines;
00001
00002
00003
00099
00100
2000
2001
2002
2019
2020
;
run;

proc format;
  value conv_id (default=5)
    0-100  = [z5.]
    other = [f5.]
  ;
quit;


data have(drop=id_orig);
  set have(rename=(id=id_orig));
  length id $5;
  id=put(id_orig,conv_id. -l);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Feb 2019 22:02:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-the-format-and-designate-length-for-two/m-p/536074#M147275</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-15T22:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do I change the format and designate length for two conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-the-format-and-designate-length-for-two/m-p/536076#M147276</link>
      <description>Please post example data showing what you have. &lt;BR /&gt;&lt;BR /&gt;This creates a char-version with leading zeros:&lt;BR /&gt;length char_id $ 5;&lt;BR /&gt;char_id = put(id, z5.);&lt;BR /&gt;&lt;BR /&gt;You have to explain how the observations that should start with two can be identified.</description>
      <pubDate>Fri, 15 Feb 2019 22:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-the-format-and-designate-length-for-two/m-p/536076#M147276</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-02-15T22:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I change the format and designate length for two conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-the-format-and-designate-length-for-two/m-p/536544#M147447</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the code. It worked!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have another question: How do I reorder the ID variable back to the first column. It is now listing in the last column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Feb 2019 18:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-the-format-and-designate-length-for-two/m-p/536544#M147447</guid>
      <dc:creator>Denali</dc:creator>
      <dc:date>2019-02-18T18:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I change the format and designate length for two conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-the-format-and-designate-length-for-two/m-p/536627#M147486</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/140136"&gt;@Denali&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Patrick,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for the code. It worked!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have another question: How do I reorder the ID variable back to the first column. It is now listing in the last column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The variable order in a table shouldn't be of real relevance but... you can have the ID column as first column simply by placing the LENGTH statement before the SET statement. This way the ID column gets defined first and though will be the first column in the new Have table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have(drop=id_orig);
  length id $5;
  set have(rename=(id=id_orig));
  id=put(id_orig,conv_id. -l);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Feb 2019 01:31:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-the-format-and-designate-length-for-two/m-p/536627#M147486</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-19T01:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do I change the format and designate length for two conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-the-format-and-designate-length-for-two/m-p/537855#M147994</link>
      <description>&lt;P&gt;Thank you Patrick.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I've got another dataset, and the ID column is character, not numeric. We still want the #1-100 to be length 5 and &amp;gt;=2000 to be length 4, just like below. I do I code it?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&lt;/P&gt;&lt;P&gt;00001&lt;/P&gt;&lt;P&gt;00002&lt;/P&gt;&lt;P&gt;00003&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;00099&lt;/P&gt;&lt;P&gt;00100&lt;/P&gt;&lt;P&gt;2000&lt;/P&gt;&lt;P&gt;2001&lt;/P&gt;&lt;P&gt;2002&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2019&lt;/P&gt;&lt;P&gt;2020&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 22 Feb 2019 20:51:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-the-format-and-designate-length-for-two/m-p/537855#M147994</guid>
      <dc:creator>Denali</dc:creator>
      <dc:date>2019-02-22T20:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do I change the format and designate length for two conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-the-format-and-designate-length-for-two/m-p/537914#M148027</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/140136"&gt;@Denali&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally create new questions as a new discussion and reference the old discussion there if it's related.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Zw. format which so nicely lets you add leading zero's is for numerical variables. If your source is a character variable containing digits only then easiest is to first convert the character to numeric and then apply the Zw. format. Based on the code I've posted earlier this could look as below:&lt;/P&gt;
&lt;PRE&gt;id=put(input(id_orig,best32.),conv_id. -l);&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Feb 2019 00:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-the-format-and-designate-length-for-two/m-p/537914#M148027</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-23T00:20:52Z</dc:date>
    </item>
  </channel>
</rss>

