<?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 Reading the values parametrically from the columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-the-values-parametrically-from-the-columns/m-p/472443#M121145</link>
    <description>&lt;P&gt;Hello experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question about reading from table. For example; I have a lookup table like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;COUNTRY_CODE&amp;nbsp;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;COUNTRY_SCORE&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;USA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 100&lt;/P&gt;&lt;P&gt;TUR&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;140&lt;/P&gt;&lt;P&gt;ENG&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;120&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create a parametric code which can find the COUNTRY_SCORE by given COUNTRY_CODE. It means when I run the code and if “USA” is given for COUNTRY_CODE I want to find the “100” for C COUNTRY_SCORE for future calculation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried something as given below but the code couldn’t resolve the macros so couldn’t find the scores.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;

%macro mAssign(VR, VL);

&amp;nbsp;

data _null_;

call symput ("&amp;amp;VR.","&amp;amp;&amp;amp;VL.");

run;

&amp;nbsp;

%mend mAssign;

&amp;nbsp;

data _null_;

set lookup_dim;

call execute('%mAssign('||LOOKUP_CODE||','||LOOKUP_NUM_VALUE||')');

run;

&amp;nbsp;

data country;

&amp;nbsp;&amp;nbsp; input COUNTRY_CODE $;

&amp;nbsp;&amp;nbsp; datalines;

USA

TUR

ENG

;run;

&amp;nbsp;

data scored_country;

set country;

if COUNTRY_CODE = "&amp;amp;LOOKUP_CODE" then country_score = &amp;amp;LOOKUP_NUM_VALUE; else country_score = 0;

run;

&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Jun 2018 11:25:45 GMT</pubDate>
    <dc:creator>FerhatD</dc:creator>
    <dc:date>2018-06-22T11:25:45Z</dc:date>
    <item>
      <title>Reading the values parametrically from the columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-the-values-parametrically-from-the-columns/m-p/472443#M121145</link>
      <description>&lt;P&gt;Hello experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question about reading from table. For example; I have a lookup table like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;COUNTRY_CODE&amp;nbsp;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;COUNTRY_SCORE&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;USA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 100&lt;/P&gt;&lt;P&gt;TUR&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;140&lt;/P&gt;&lt;P&gt;ENG&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;120&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create a parametric code which can find the COUNTRY_SCORE by given COUNTRY_CODE. It means when I run the code and if “USA” is given for COUNTRY_CODE I want to find the “100” for C COUNTRY_SCORE for future calculation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried something as given below but the code couldn’t resolve the macros so couldn’t find the scores.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;

%macro mAssign(VR, VL);

&amp;nbsp;

data _null_;

call symput ("&amp;amp;VR.","&amp;amp;&amp;amp;VL.");

run;

&amp;nbsp;

%mend mAssign;

&amp;nbsp;

data _null_;

set lookup_dim;

call execute('%mAssign('||LOOKUP_CODE||','||LOOKUP_NUM_VALUE||')');

run;

&amp;nbsp;

data country;

&amp;nbsp;&amp;nbsp; input COUNTRY_CODE $;

&amp;nbsp;&amp;nbsp; datalines;

USA

TUR

ENG

;run;

&amp;nbsp;

data scored_country;

set country;

if COUNTRY_CODE = "&amp;amp;LOOKUP_CODE" then country_score = &amp;amp;LOOKUP_NUM_VALUE; else country_score = 0;

run;

&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jun 2018 11:25:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-the-values-parametrically-from-the-columns/m-p/472443#M121145</guid>
      <dc:creator>FerhatD</dc:creator>
      <dc:date>2018-06-22T11:25:45Z</dc:date>
    </item>
    <item>
      <title>Re: Reading the values parametrically from the columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-the-values-parametrically-from-the-columns/m-p/472448#M121147</link>
      <description>&lt;P&gt;Why not use the small lookup table - I'm calling it country_lookup - in a hash join to the larger table with countries? Seems more straightforward than complex macro code. If you haven't used a hash join before, it's a simple in data step way to combine tables and often more computationally efficient than proc sql or a sort-merge.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data has_country_score;
	length country_score 8.;
	if _n_ eq 1 then do;
		declare hash ctry_hash(dataset:'country_lookup');
		ctry_hash.definekey('country_code');
		ctry_hash.definedata('country_score');
		ctry_hash.definedone();
		call missing(country_score);
	end;

	set big_table_with_countries;

	rcLOOKUP = ctry_hash.find(); /*Will be 0 if there is a match*/
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Jun 2018 12:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-the-values-parametrically-from-the-columns/m-p/472448#M121147</guid>
      <dc:creator>lrudolphi</dc:creator>
      <dc:date>2018-06-22T12:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Reading the values parametrically from the columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-the-values-parametrically-from-the-columns/m-p/472465#M121150</link>
      <description>&lt;P&gt;There are several ways to skin this cat. One is to create an informat, e.g.:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input
COUNTRY_CODE  $ COUNTRY_SCORE;
cards;
USA 100
TUR 140
ENG 120
;run;

filename tempsas temp;
data _null_;
  set have end=done;
  file tempsas;
  if _N_=1 then
    put 'invalue score';
  put country_code $quote. '=' country_score;
  if done then
    put 'other=.;';
run;

proc format;
  %include tempsas /source2;
run;

data _null_;
  a='USA';
  b=input(a,score.);
  put _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Another is to create an index and use that for lookup:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create index country_code on have(country_code);
quit;

data _null_;
  input a $;
  set have(rename=(country_code=a)) key=a/unique;
  if _iorc_ then do;
    _error_=0;
    country_score=.;
    end;
  put _all_;
cards;
TUR
USA
FFF
;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Jun 2018 13:03:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-the-values-parametrically-from-the-columns/m-p/472465#M121150</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-06-22T13:03:50Z</dc:date>
    </item>
  </channel>
</rss>

