<?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: A question about SAS functions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757784#M239227</link>
    <description>&lt;P&gt;Thank you all for the explanations.&lt;BR /&gt;&lt;BR /&gt;Reeza,&lt;BR /&gt;amt='0089000]' is part of the code.&lt;BR /&gt;&lt;BR /&gt;Bulk data from FEC is fairly clean and that is why I was wondering why this code is needed as I think the amount column looks a normal numerical variable.&lt;BR /&gt;&lt;BR /&gt;Now I have an idea of what this code is supposed to do but I could not get why the code multiply by -10 and subtract one (-1). These are amounts, is this changing the amounts in any how?&lt;/P&gt;</description>
    <pubDate>Wed, 28 Jul 2021 16:25:17 GMT</pubDate>
    <dc:creator>Khno</dc:creator>
    <dc:date>2021-07-28T16:25:17Z</dc:date>
    <item>
      <title>A question about SAS functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757763#M239217</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;
&lt;P&gt;I found the below code online. It is used to correct issues with the contribution amounts from the Federal Election Committee database (FEC.gov). I do not understand what exactly this code suppose to do. I would appreciate it if you could please explain the purpose of doing this to the amount column in the data.&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;
&lt;P&gt;***Correcting issues with contribution amount in the data;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;

amt='008900]';

b=input(compress(amt,"jklmnopqr]","i"),8.)*(-10)-(find(']jklmnopqr',lowcase(substr(amt,notdigit(amt))))-1);;

put b;

run;



%macro amt;

%let yrlist=00 02 04 06 08 80 82 84 86 88 90 92 94 96 98;

%do i=1 %to 15;

%let yr=%scan(&amp;amp;yrlist,&amp;amp;i);



data r.ind&amp;amp;yr;

set r.ind&amp;amp;yr;

if notdigit(amt)=0 then amt_new=input(put(amt,8.),8.);

else

amt_new=input(compress(amt,"jklmnopqr]","i"),8.)*(-10)-(find(']jklmnopqr',lowcase(substr(amt,notdigit(amt))))-1);

run;



%end;



%mend;



%amt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Jul 2021 15:59:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757763#M239217</guid>
      <dc:creator>Khno</dc:creator>
      <dc:date>2021-07-28T15:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: A question about SAS functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757767#M239220</link>
      <description>&lt;P&gt;Presumably, amounts should be numeric.&amp;nbsp; The Compress function compresses out (removes) unwanted characters.&amp;nbsp; It appears that they are removing alphabetic characters.&amp;nbsp; There are other ways to do this such as coding 'kd' (keep digits) as the third parameter of Compress, but here they're coding the characters individually, and they're just coding "&lt;SPAN&gt;jklmnopqr"&lt;/SPAN&gt;.&amp;nbsp; I can't tell you why those specific characters would be important.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can see that the Compress is only done if a non-numeric is found in this If statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if  notdigit(amt)=0 then amt_new=input(put(amt,8.),8.);
else
    amt_new=input(compress(amt,"jklmnopqr]","i"),8.)*(-10)-(find(']jklmnopqr',lowcase(substr(amt,notdigit(amt))))-1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 16:00:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757767#M239220</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-28T16:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: A question about SAS functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757769#M239222</link>
      <description>If you compare the input to the output that should give you a general idea of what's happening, in general it seems to be cleaning the field. &lt;BR /&gt;&lt;BR /&gt;COMPRESS() removes characters specified. &lt;BR /&gt;FIND() searches for characters and returns the index when the specified character is found. &lt;BR /&gt;NOTDIGIT() checks if any non digit characters are in a string.&lt;BR /&gt;SUBSTR() takes part of a string&lt;BR /&gt;LOWCASE() converts everything to lower case&lt;BR /&gt;INPUT() converts a character to numeric. &lt;BR /&gt;&lt;BR /&gt;Now tie those to what you have as the input value and see how it can be used to create your output value. &lt;BR /&gt;&lt;BR /&gt;Is amt='0089000]' your example of how the the amt field originally looks? That wasn't clear from your example or code.&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Jul 2021 15:58:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757769#M239222</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-07-28T15:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: A question about SAS functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757770#M239223</link>
      <description>&lt;P&gt;Which specific functions do you not understand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to see what is happening in specific is to pull the syntax apart (good lesson itself);&lt;/P&gt;
&lt;P&gt;Such as&lt;/P&gt;
&lt;PRE&gt;data junk;

amt='008900]';
A = compress(amt,"jklmnopqr]","i");
b = input(A,8.);
c = notdigit(amt);
d = substr(amt,c);
e = lowcase(d);
f = find(']jklmnopqr',d);

run;

&lt;/PRE&gt;
&lt;P&gt;Apparently the coder wanted a numeric value from a field that is supplied with additional codes , the values that appear in the string "jklmnopqr]". The various functions find the bits not related to the numeric value and remove them using some external not provided rules to create a desired range.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro then dangerously loops through a number of similarly named data sets and hopefully adds a similarly created numeric value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do I say "dangerously"? Any code that uses the same data set as the source, Set statement, and output, Data statement, completely replaces the source data set if no errors are encountered. A logic error or typo might accidentally replace a value not intended.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 16:06:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757770#M239223</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-28T16:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: A question about SAS functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757773#M239225</link>
      <description>Is someone scraping data or downloading from the bulk files? The bulk files are fairly clean are they not?</description>
      <pubDate>Wed, 28 Jul 2021 16:08:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757773#M239225</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-07-28T16:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: A question about SAS functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757784#M239227</link>
      <description>&lt;P&gt;Thank you all for the explanations.&lt;BR /&gt;&lt;BR /&gt;Reeza,&lt;BR /&gt;amt='0089000]' is part of the code.&lt;BR /&gt;&lt;BR /&gt;Bulk data from FEC is fairly clean and that is why I was wondering why this code is needed as I think the amount column looks a normal numerical variable.&lt;BR /&gt;&lt;BR /&gt;Now I have an idea of what this code is supposed to do but I could not get why the code multiply by -10 and subtract one (-1). These are amounts, is this changing the amounts in any how?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 16:25:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757784#M239227</guid>
      <dc:creator>Khno</dc:creator>
      <dc:date>2021-07-28T16:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: A question about SAS functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757813#M239232</link>
      <description>&lt;P&gt;Again, you'll need to check the before and after. Adding a bunch of print statements (PUT in SAS) is old school but it helps you debug these things quite well. &lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro amt;

%let yrlist=00 02 04 06 08 80 82 84 86 88 90 92 94 96 98;

%do i=1 %to 15;

%let yr=%scan(&amp;amp;yrlist,&amp;amp;i);

%put &amp;amp;yr.;


data r.ind&amp;amp;yr;

set r.ind&amp;amp;yr;
put "AMT = " amt;
if notdigit(amt)=0 then amt_new=input(put(amt,8.),8.);

else

amt_new=input(compress(amt,"jklmnopqr]","i"),8.)*(-10)-(find(']jklmnopqr',lowcase(substr(amt,notdigit(amt))))-1);

put "AMT_NEW=" AMT_NEW;

run;



%end;



%mend;



%amt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Jul 2021 18:10:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757813#M239232</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-07-28T18:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: A question about SAS functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757845#M239242</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/391425"&gt;@Khno&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like the purpose of this code is to read (so called) &lt;EM&gt;zoned decimal&lt;/EM&gt; values, likely originating from an IBM mainframe system, into a numeric variable. See&amp;nbsp;&lt;A href="https://en.wikipedia.org/wiki/Binary-coded_decimal#Zoned_decimal" target="_blank"&gt;https://en.wikipedia.org/wiki/Binary-coded_decimal#Zoned_decimal&lt;/A&gt;&amp;nbsp;for the explanation how &lt;EM&gt;negative&lt;/EM&gt; values are coded by replacing the last digit (&lt;FONT face="courier new,courier"&gt;0, 1, 2, 3, ..., 9&lt;/FONT&gt;) with a particular non-numeric character (&lt;FONT face="courier new,courier"&gt;}, J, K, L, ..., R&lt;/FONT&gt;)&amp;nbsp; -- where "&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;" might "&lt;I&gt;vary depending on the local character&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A title="" href="https://en.wikipedia.org/wiki/Code_page" target="_blank"&gt;code page&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;setting."&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then the multiplication by &lt;FONT face="courier new,courier"&gt;-10&lt;/FONT&gt; and the subtraction of &lt;FONT face="courier new,courier"&gt;1&lt;/FONT&gt;&amp;nbsp;in your code make perfect sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's possible, though, that you don't even need this manual conversion because SAS provides informats to deal with various sorts of zoned decimal data, for example the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/p15zzcwdrbo708n1owjn1oscogx1.htm" target="_blank" rel="noopener"&gt;ZDw.d informat&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
input amt $;
b=input(translate(amt,'}',']'),zd7.);
put b 6.;
cards;
008900]
008900J
008900K
008900R
0089000
0089002
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result (on a German Windows system):&lt;/P&gt;
&lt;PRE&gt;-89000
-89001
-89002
-89009
 89000
 89002&lt;/PRE&gt;
&lt;P&gt;As mentioned above, using the TRANSLATE function might not be necessary on other systems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, note that the PUT function in&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;input(put(amt,8.),8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is used inappropriately (and can be omitted), assuming variable &lt;FONT face="courier new,courier"&gt;amt&lt;/FONT&gt; is already character.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 18:01:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757845#M239242</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-07-28T18:01:56Z</dc:date>
    </item>
    <item>
      <title>Re: A question about SAS functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757857#M239245</link>
      <description>I should clarify Bulk data from FEC is fairly clean now....it's very much possible that it wasn't when the coder was working on it. &lt;BR /&gt;If I was doing this, I'd verify the file was being read correctly based on current specifications and if there wasn't a way to fix some of this using formats as indicated by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;. &lt;BR /&gt;I've seen that issue with public data feeds before over time....</description>
      <pubDate>Wed, 28 Jul 2021 18:13:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-question-about-SAS-functions/m-p/757857#M239245</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-07-28T18:13:19Z</dc:date>
    </item>
  </channel>
</rss>

