<?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 Two different formats under one variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Two-different-formats-under-one-variable/m-p/911374#M359394</link>
    <description>&lt;P&gt;I am aware that formats follow variables however, I would like to know if there is a way&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to have two formats under one variable? For example, the code below pulls data in and&amp;nbsp;&lt;/P&gt;
&lt;P&gt;all variables are character variables. The data is split into two datasets and formatted.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The two datasets are then stacked to create one variable called estimate. The estimate&amp;nbsp;&lt;/P&gt;
&lt;P&gt;variable should hold numeric values which are comma formatted and decimal values. However,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the decimals are dropped because the variable is now based on the comma value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input year $ number $ percent $; &lt;BR /&gt;cards; &lt;BR /&gt;2018 515 29.1 &lt;BR /&gt;2018 4526 33.3&lt;BR /&gt;2018 26518936 56.1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Create two separate datasets: 1)numbers with comma format 2)percent with decimal format*/&lt;BR /&gt;data number (drop=percent number); &lt;BR /&gt;set have; &lt;BR /&gt;estimate = input(number,best.);&lt;BR /&gt;format estimate comma10.0;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data percent (drop=number and percent); &lt;BR /&gt;set have; &lt;BR /&gt;estimate = input(percent,best.);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Stack datasets*/&lt;BR /&gt;data wrong; &lt;BR /&gt;set number percent;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what I get using the above code:&lt;/P&gt;
&lt;TABLE width="138"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50.125px" height="30px"&gt;Year&lt;/TD&gt;
&lt;TD width="86.875px" height="30px"&gt;Estimate&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50.125px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.875px" height="30px"&gt;515&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50.125px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.875px" height="30px"&gt;4,526&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50.125px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.875px" height="30px"&gt;26,518,936&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50.125px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.875px" height="30px"&gt;29&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50.125px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.875px" height="30px"&gt;33&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50.125px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.875px" height="30px"&gt;56&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what I would like to have:&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="137px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="49.0156px" height="30px"&gt;Year&lt;/TD&gt;
&lt;TD width="86.9844px" height="30px"&gt;Estimate&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="49.0156px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.9844px" height="30px"&gt;515&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="49.0156px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.9844px" height="30px"&gt;4,526&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="49.0156px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.9844px" height="30px"&gt;26,518,936&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="49.0156px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.9844px" height="30px"&gt;29.1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="49.0156px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.9844px" height="30px"&gt;33.3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="49.0156px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.9844px" height="30px"&gt;56.1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Does a way exist to make this dataset happen?&lt;/P&gt;</description>
    <pubDate>Fri, 12 Jan 2024 11:56:18 GMT</pubDate>
    <dc:creator>luvscandy27</dc:creator>
    <dc:date>2024-01-12T11:56:18Z</dc:date>
    <item>
      <title>Two different formats under one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-different-formats-under-one-variable/m-p/911374#M359394</link>
      <description>&lt;P&gt;I am aware that formats follow variables however, I would like to know if there is a way&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to have two formats under one variable? For example, the code below pulls data in and&amp;nbsp;&lt;/P&gt;
&lt;P&gt;all variables are character variables. The data is split into two datasets and formatted.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The two datasets are then stacked to create one variable called estimate. The estimate&amp;nbsp;&lt;/P&gt;
&lt;P&gt;variable should hold numeric values which are comma formatted and decimal values. However,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the decimals are dropped because the variable is now based on the comma value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input year $ number $ percent $; &lt;BR /&gt;cards; &lt;BR /&gt;2018 515 29.1 &lt;BR /&gt;2018 4526 33.3&lt;BR /&gt;2018 26518936 56.1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Create two separate datasets: 1)numbers with comma format 2)percent with decimal format*/&lt;BR /&gt;data number (drop=percent number); &lt;BR /&gt;set have; &lt;BR /&gt;estimate = input(number,best.);&lt;BR /&gt;format estimate comma10.0;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data percent (drop=number and percent); &lt;BR /&gt;set have; &lt;BR /&gt;estimate = input(percent,best.);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Stack datasets*/&lt;BR /&gt;data wrong; &lt;BR /&gt;set number percent;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what I get using the above code:&lt;/P&gt;
&lt;TABLE width="138"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50.125px" height="30px"&gt;Year&lt;/TD&gt;
&lt;TD width="86.875px" height="30px"&gt;Estimate&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50.125px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.875px" height="30px"&gt;515&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50.125px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.875px" height="30px"&gt;4,526&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50.125px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.875px" height="30px"&gt;26,518,936&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50.125px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.875px" height="30px"&gt;29&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50.125px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.875px" height="30px"&gt;33&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50.125px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.875px" height="30px"&gt;56&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what I would like to have:&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="137px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="49.0156px" height="30px"&gt;Year&lt;/TD&gt;
&lt;TD width="86.9844px" height="30px"&gt;Estimate&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="49.0156px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.9844px" height="30px"&gt;515&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="49.0156px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.9844px" height="30px"&gt;4,526&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="49.0156px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.9844px" height="30px"&gt;26,518,936&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="49.0156px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.9844px" height="30px"&gt;29.1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="49.0156px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.9844px" height="30px"&gt;33.3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="49.0156px" height="30px"&gt;2018&lt;/TD&gt;
&lt;TD width="86.9844px" height="30px"&gt;56.1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Does a way exist to make this dataset happen?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2024 11:56:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-different-formats-under-one-variable/m-p/911374#M359394</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2024-01-12T11:56:18Z</dc:date>
    </item>
    <item>
      <title>Re: Two different formats under one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-different-formats-under-one-variable/m-p/911375#M359395</link>
      <description>&lt;P&gt;If it has to be a SAS data set with two different formats for a single variable, then this is not possible. Nor can I think of a reason why you would want to do this, as the purpose of a SAS data set is to contain data. The data is the same, regardless of how it is formatted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if you are creating a report from a SAS data set, then yes, it does make sense to do this, and you can have two (or more!) different formats in a column by using PROC REPORT. See&amp;nbsp;&lt;A href="https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-different-formats-for-different-rows/td-p/403157" target="_blank" rel="noopener"&gt;PROC REPORT — different formats for different rows? - SAS Support Communities&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2024 12:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-different-formats-under-one-variable/m-p/911375#M359395</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-01-12T12:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: Two different formats under one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-different-formats-under-one-variable/m-p/911377#M359397</link>
      <description>&lt;P&gt;Don't forget that formats only affect how values get displayed and not how they get stored internally. You can always change the format applied to variable - permanently or temporarily. With your code try below and see what happens.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Stack datasets*/
data wrong;
  set number percent;
  format estimate best32.4;
run;

proc print data=wrong;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Jan 2024 12:25:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-different-formats-under-one-variable/m-p/911377#M359397</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-01-12T12:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: Two different formats under one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-different-formats-under-one-variable/m-p/911383#M359398</link>
      <description>&lt;P&gt;First, note that you can do this.&amp;nbsp; You would have to define (and apply) your own format along these lines:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
   value some_commas 100-high = [comma10.0]
    other=[5.1];
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then in your FORMAT statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format myvar some_commas.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You probably will want to examine the results and possibly apply centering as the default for the format.&amp;nbsp; But try this much first and see how far it takes you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will need to apply a rule, as is done here.&amp;nbsp; For example, everything that is less than 100 prints with a decimal point.&amp;nbsp; It won't matter what data set the value came from.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2024 13:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-different-formats-under-one-variable/m-p/911383#M359398</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2024-01-12T13:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: Two different formats under one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-different-formats-under-one-variable/m-p/911495#M359422</link>
      <description>&lt;P&gt;There are already solutions proposed that will return what you've asked for but... Looking at your data again does it really make sense to mix "absolute" numbers and percentages in the same column? How would you separate them for any calculations? If this is just about some report then consider something like below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input year $ number $ percent $;
  datalines;
2018 515 29.1
2018 4526 33.3
2018 26518936 56.1
;

proc sql;
  select year, 'number' as type, number as estimate
  from have
  union all
  select year, 'percent' as type, percent as estimate
  from have
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Jan 2024 02:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-different-formats-under-one-variable/m-p/911495#M359422</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-01-14T02:00:58Z</dc:date>
    </item>
  </channel>
</rss>

