<?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: Dollar and Comma format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dollar-and-Comma-format/m-p/841338#M332667</link>
    <description>&lt;P&gt;You have created variable AMOUNT as a character variable. It must be numeric in order to use the COMMA format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, there's really no reason for AMOUNT to be character, it really is numeric.&lt;/P&gt;</description>
    <pubDate>Fri, 28 Oct 2022 16:29:53 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-10-28T16:29:53Z</dc:date>
    <item>
      <title>Dollar and Comma format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dollar-and-Comma-format/m-p/841336#M332665</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Background info on the assignment:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;STAT 325 HOMEWORK 6 
sql 
Data  description:  Kroger  warehouse,  which  has  two  hubs,  supplies  5  supermarkets  in  local  San  Diego.  
You may want to analyze the sale and logistic record of 2014 by using “proc sql” in SAS.  
market.csv:   
Column 1: Item ID; 
Column 2: Item Name; 
Column 3: Unit Price; 
Column 4: Sale Amount;  
Column 5: Store Branch; 
 
warehouse.csv: 
Column 1: Item ID; 
Column 2: Item Name; 
Column 3: Warehouse Hub Name; 
Column 4: Store Branch;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN class=""&gt;Code:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*Question 1*/
data market;
length item $20. branch $20. id $6. price $2. amount $15.;
infile '/home/u62108616/sasuser.v94/S325/market.csv' dsd truncover;
format price DOLLAR1.2 amount COMMA15.0;
run;

proc sql;
select*
from market;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;Error Messages/Warnings:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;NOTE 484-185: Format $DOLLAR was not found or could not be loaded.
 
 ERROR 230-185: Invalid character format/informat decimal specified.
 
 73       ! format price DOLLAR1.2 amount COMMA15.0;
                                          _________
                                          484
 NOTE 484-185: Format $COMMA was not found or could not be loaded.
 
 74         run;
 
 NOTE: The SAS System stopped processing this step because of errors.
 WARNING: The data set WORK.MARKET may be incomplete.  When this step was stopped there were 0 observations and 5 variables.
 WARNING: Data set WORK.MARKET was not replaced because this step was stopped.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Question 1:&amp;nbsp;&amp;nbsp;Read in the market.csv data file, apply the dollar w.d format and comma separated format to the variables&lt;BR /&gt;of price and amount&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;What am I doing wrong here and how should I fix it?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 16:28:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dollar-and-Comma-format/m-p/841336#M332665</guid>
      <dc:creator>JoshuaG</dc:creator>
      <dc:date>2022-10-28T16:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Dollar and Comma format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dollar-and-Comma-format/m-p/841338#M332667</link>
      <description>&lt;P&gt;You have created variable AMOUNT as a character variable. It must be numeric in order to use the COMMA format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, there's really no reason for AMOUNT to be character, it really is numeric.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 16:29:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dollar-and-Comma-format/m-p/841338#M332667</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-28T16:29:53Z</dc:date>
    </item>
    <item>
      <title>Re: Dollar and Comma format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dollar-and-Comma-format/m-p/841339#M332668</link>
      <description>&lt;P&gt;Your LENGTH statement made AMOUNT a character variable.&amp;nbsp; Change its length to 8 (no dollar sign).&amp;nbsp; Same applies to other variables such as PRICE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, you didn't input any variables from the data.&amp;nbsp; You should probably add an INPUT statement to the first DATA step.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 16:31:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dollar-and-Comma-format/m-p/841339#M332668</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-10-28T16:31:46Z</dc:date>
    </item>
    <item>
      <title>Re: Dollar and Comma format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dollar-and-Comma-format/m-p/841345#M332671</link>
      <description>&lt;P&gt;It is good to use the LENGTH statement to explicitly define the variables.&amp;nbsp; But you should not define the numeric variables as character.&amp;nbsp; Also you do not need to include a decimal point when defining the length.&amp;nbsp; The length can only be an integer value so no decimal point is needed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length item $20 branch $20 id $6 price amount 8;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You still need to tell SAS to actually read the variables from the lines of the CSV file by adding an INPUT statement.&lt;/P&gt;
&lt;P&gt;You cannot have a display width that has more decimal places than the total width.&amp;nbsp; Fix the width used on the DOLLAR format specification.&amp;nbsp; Make sure to take into account room for the decimal point (if requested), the $ character and any thousands block separators (commas).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data market;
  length item $20 branch $20 id $6 price amount 8;
  infile '/home/u62108616/sasuser.v94/S325/market.csv' dsd truncover;
  input item branch id price amount;
  format price DOLLAR12.2 amount COMMA15.0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;No need to use SQL to print data.&amp;nbsp; Just use PROC PRINT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=market;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also does the CSV files have a header line or not?&amp;nbsp; If so you will want to add the FIRSTOBS=2 option to the INFILE statement to tell it to skip the header line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 16:46:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dollar-and-Comma-format/m-p/841345#M332671</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-28T16:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: Dollar and Comma format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dollar-and-Comma-format/m-p/841353#M332675</link>
      <description>&lt;P&gt;Current Output vs Intended Output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot (1217).png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76725i59E3653BB3880920/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot (1217).png" alt="Screenshot (1217).png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot (1218).png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76726i29D9A14360E68B5A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot (1218).png" alt="Screenshot (1218).png" /&gt;&lt;/span&gt;&lt;BR /&gt;Updated Code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*Question 1*/
data market; 
length item $20. branch $20. id $6. price 3. amount 8.;
infile '/home/u62108616/sasuser.v94/S325/market.csv' dsd truncover;
input item $ branch $ id $ price amount;
format price DOLLAR10.2 amount COMMA15.0;
run;

proc sql;
select*
from market;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I know question 1 doesnt correlate to any of the tables produced in the intended output, however, it seems like my variables are still a bit messed up&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 16:59:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dollar-and-Comma-format/m-p/841353#M332675</guid>
      <dc:creator>JoshuaG</dc:creator>
      <dc:date>2022-10-28T16:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: Dollar and Comma format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dollar-and-Comma-format/m-p/841360#M332679</link>
      <description>&lt;P&gt;The LENGTH statement sets the&amp;nbsp;&lt;EM&gt;storage length&lt;/EM&gt; of variables. For numeric variables, leave it at 8, or you will lose precision unnecessarily.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 18:13:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dollar-and-Comma-format/m-p/841360#M332679</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-28T18:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Dollar and Comma format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dollar-and-Comma-format/m-p/841362#M332680</link>
      <description>&lt;P&gt;Also, your INPUT statement does not reflect the order of variables in the assignment. id should be last.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 18:17:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dollar-and-Comma-format/m-p/841362#M332680</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-28T18:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: Dollar and Comma format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dollar-and-Comma-format/m-p/841365#M332682</link>
      <description>&lt;P&gt;The LENGTH statement has NOTHING to do with FORMATS (of INFORMATS).&amp;nbsp; It is for telling SAS what type of variable you want to create and how much space it takes to store it in the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do not add periods to the lengths.&amp;nbsp; Do not tell SAS to store only the first 3 bytes of the 8 bytes needed to represent a floating point number. Remember that SAS only has two types of variables: fixed length character strings and 64bit floating point numbers.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length item $20 branch $20 id $6 price amount 8;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It also looks like your input statement does not match the data in the text file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It could be the CSV is corrupt or mall formed. Why would the ID values have periods in them?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to why the AMOUNT variable is missing we probably need to see the LOG (please post the text of the log and not another photograph) and perhaps also the text of some of the lines from the CSV file.&amp;nbsp; If you cannot figure out how to view the text of the CSV file then you can add the LIST statement to your SAS data step and SAS will display the lines read from the CSV file into the SAS log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 18:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dollar-and-Comma-format/m-p/841365#M332682</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-28T18:28:57Z</dc:date>
    </item>
  </channel>
</rss>

