<?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: Automate code with character variable taking varying values in data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Automate-code-with-character-variable-taking-varying-values-in/m-p/554696#M154343</link>
    <description>&lt;P&gt;It's certainly possible to set up the known translations as a data set.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data master_list;
input location $ code $ site weight;
datalines;
A 153 1 1
A 154 1 1
A 157 0 2
B 183 1 1
B 185 1 1
B 196 0 2
C 200 1 1
C 100 0 2
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then the approach would be to use this as a hash table, where the key is the combination of CODE and LOCATION, and the data is the SITE and WEIGHT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, note that the logic is not just a matter of look-up.&amp;nbsp; You have to check whether the table actually contains the combination you are searching for.&amp;nbsp; If it does, great you can use the values found via look-up.&amp;nbsp; But if it doesn't, you still need to set SITE to 0 and WEIGHT to 99.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is something that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;can do in his sleep, so I will abandon the coding efforts.&lt;/P&gt;</description>
    <pubDate>Mon, 29 Apr 2019 13:45:06 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-04-29T13:45:06Z</dc:date>
    <item>
      <title>Automate code with character variable taking varying values in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automate-code-with-character-variable-taking-varying-values-in/m-p/554682#M154338</link>
      <description>&lt;P&gt;Hello Folks,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I'm trying to subset a large data to fourty smaller datasets based on the "location"&amp;nbsp; AND "code" variables.&lt;/P&gt;
&lt;P&gt;Codes are taking different values in datasteps depending on whether sites are A or B or C.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to reduce human error by automating this subsetting process. &lt;/P&gt;
&lt;P&gt;Is there any way? I'm familiar to macro/mend process. But I don't know how when character variable is involved taking different values.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE; 
INPUT ID CODE $ LOCATION $;
CARDS;
1	154	A
1	157	A
1	C25	A
1	153	A
2	183	B
2	185	B
2	196	B
2	196	B
3       200     C
3       100     C 
;

DATA SUBSET_A(COMPRESS=YES);
SET HAVE(WHERE=(LOCATION="A"));
IF CODE IN ('153','154') THEN SITE=1; ELSE SITE=0;
IF CODE IN ('153','154') THEN WEIGHT=1; ELSE
IF CODE IN ('157') THEN WEIGHT=2; ELSE WEIGHT=99;
RUN;

DATA SUBSET_B(COMPRESS=YES);
SET HAVE(WHERE=(LOCATION="B"));
IF CODE IN ('183','185') THEN SITE=1; ELSE SITE=0;
IF CODE IN ('183','185') THEN WEIGHT=1; ELSE
IF CODE IN ('196') THEN WEIGHT=2; ELSE WEIGHT=99;
RUN;

DATA SUBSET_C(COMPRESS=YES);
SET HAVE(WHERE=(LOCATION="C"));
IF CODE IN ('200') THEN SITE=1; ELSE SITE=0;
IF CODE IN ('200') THEN WEIGHT=1; ELSE
IF CODE IN ('100') THEN WEIGHT=2; ELSE WEIGHT=99;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2019 13:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automate-code-with-character-variable-taking-varying-values-in/m-p/554682#M154338</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2019-04-29T13:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Automate code with character variable taking varying values in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automate-code-with-character-variable-taking-varying-values-in/m-p/554685#M154339</link>
      <description>&lt;P&gt;splitting into many data sets based on LOCATION is pretty straight forward&amp;nbsp; however in your case I wonder how would you automate the condition of the CODE values that constitutes to SITE variables as each of seems to be mutually exclusive&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2019 13:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automate-code-with-character-variable-taking-varying-values-in/m-p/554685#M154339</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-29T13:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: Automate code with character variable taking varying values in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automate-code-with-character-variable-taking-varying-values-in/m-p/554690#M154341</link>
      <description>&lt;P&gt;That's the problem. I wonder if it's possible to define a specific set of 'codes' for the specific combinations of 'Location-site-weight'? as a dictionary to refer? and SAS subsets data with the reference of info in that dictionary? something like that?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2019 13:29:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automate-code-with-character-variable-taking-varying-values-in/m-p/554690#M154341</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2019-04-29T13:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: Automate code with character variable taking varying values in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automate-code-with-character-variable-taking-varying-values-in/m-p/554691#M154342</link>
      <description>&lt;P&gt;May be you can define user defined formats using proc format which would be a one time effort to type carefully. In any case, I really do think that's gonna take some boring effort at least once.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2019 13:32:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automate-code-with-character-variable-taking-varying-values-in/m-p/554691#M154342</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-29T13:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: Automate code with character variable taking varying values in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automate-code-with-character-variable-taking-varying-values-in/m-p/554696#M154343</link>
      <description>&lt;P&gt;It's certainly possible to set up the known translations as a data set.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data master_list;
input location $ code $ site weight;
datalines;
A 153 1 1
A 154 1 1
A 157 0 2
B 183 1 1
B 185 1 1
B 196 0 2
C 200 1 1
C 100 0 2
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then the approach would be to use this as a hash table, where the key is the combination of CODE and LOCATION, and the data is the SITE and WEIGHT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, note that the logic is not just a matter of look-up.&amp;nbsp; You have to check whether the table actually contains the combination you are searching for.&amp;nbsp; If it does, great you can use the values found via look-up.&amp;nbsp; But if it doesn't, you still need to set SITE to 0 and WEIGHT to 99.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is something that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;can do in his sleep, so I will abandon the coding efforts.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2019 13:45:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automate-code-with-character-variable-taking-varying-values-in/m-p/554696#M154343</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-04-29T13:45:06Z</dc:date>
    </item>
  </channel>
</rss>

