<?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: Match numeric values in results with reference file containing string values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Match-numeric-values-in-results-with-reference-file-containing/m-p/913120#M359911</link>
    <description>&lt;P&gt;Hello&lt;BR /&gt;Based upon your first two datasets &lt;STRONG&gt;results&lt;/STRONG&gt; and&lt;STRONG&gt; reference&lt;/STRONG&gt; the outcome does not appear to be what you have shown.&lt;BR /&gt;However using the sample code you should be able to get the desired result as shown&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data results;
input ID resultA resultB;
datalines;
1 2392 887
2 1587 902
3 2392 234
4 4035 2392
;
run;
data reference;
input num first$ last$;
datalines;
2392 joe bloggs
4035 mary smith
1587 bloggs joe
234 sherlock holmes 
902 john watson
887 benjamin button
;
run;

proc sql;
Select id, cat(Propcase(strip(first)),"-",propcase(Strip(last))) as Name from results a,reference b
where a.resultA=b.num;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The code gives result like this with the given datasets results and reference.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sajid01_0-1706277863218.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92994iEE47D9B92512D413/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sajid01_0-1706277863218.png" alt="Sajid01_0-1706277863218.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 26 Jan 2024 14:05:14 GMT</pubDate>
    <dc:creator>Sajid01</dc:creator>
    <dc:date>2024-01-26T14:05:14Z</dc:date>
    <item>
      <title>Match numeric values in results with reference file containing string values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-numeric-values-in-results-with-reference-file-containing/m-p/913109#M359905</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a results output with study participant IDs and numeric values&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data results;
input ID resultA resultB;
datalines;
1 2392 887
2 1587 902
3 2392 234
4 4035 2392
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These numeric values correspond to string values (names) found in a reference file&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data reference;
input num first$ last$;
datalines;
2392 joe bloggs
4035 mary smith
1587 bloggs joe
234 sherlock holmes 
902 john watson
887 benjamin button
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want to match the string values in the reference file with the numeric values in the results output.&lt;BR /&gt;This is the output I want to achieve; the string values under resultA and resultB are based &lt;BR /&gt;on the numbers and corresponding string values in the reference file&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input ID resultA :$200. resultB :$200. ;
datalines;
1 joe-bloggs benjamin-button
2 bloggs-joe john-watson
3 joe-bloggs sherlock-holmes
4 mary-smith joe-bloggs
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have tried to search for code on the forum to solve this, with no success.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know if my problem is not clear from the above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2024 13:21:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-numeric-values-in-results-with-reference-file-containing/m-p/913109#M359905</guid>
      <dc:creator>Epi_Stats</dc:creator>
      <dc:date>2024-01-26T13:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: Match numeric values in results with reference file containing string values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-numeric-values-in-results-with-reference-file-containing/m-p/913116#M359909</link>
      <description>&lt;P&gt;You have to join Results and Reference tables. I'm suggesting to use proc SQL for joining because there is two joins and tables doesn't have common variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;data results;&lt;/DIV&gt;
&lt;DIV&gt;input ID resultA resultB;&lt;/DIV&gt;
&lt;DIV&gt;datalines;&lt;/DIV&gt;
&lt;DIV&gt;1 2392 887&lt;/DIV&gt;
&lt;DIV&gt;2 1587 902&lt;/DIV&gt;
&lt;DIV&gt;3 2392 234&lt;/DIV&gt;
&lt;DIV&gt;4 4035 2392&lt;/DIV&gt;
&lt;DIV&gt;;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;data reference;&lt;/DIV&gt;
&lt;DIV&gt;input num first $ last $;&lt;/DIV&gt;
&lt;DIV&gt;datalines;&lt;/DIV&gt;
&lt;DIV&gt;2392 joe bloggs&lt;/DIV&gt;
&lt;DIV&gt;4035 mary smith&lt;/DIV&gt;
&lt;DIV&gt;1587 bloggs joe&lt;/DIV&gt;
&lt;DIV&gt;234 sherlock holmes&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;902 john watson&lt;/DIV&gt;
&lt;DIV&gt;887 benjamin button&lt;/DIV&gt;
&lt;DIV&gt;;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc sql;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; create table want as&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; select R.ID,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Catx('-',r1.First,r1.Last) as First,&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Catx('-',r2.First,r2.Last) as Second&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;from&amp;nbsp; &amp;nbsp; &amp;nbsp;Results R&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;left join Reference R1&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; on r.ResultA = r1.num&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;left join Reference R2&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; on r.ResultB = r2.num&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;order by r.ID;&lt;/DIV&gt;
&lt;DIV&gt;quit;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2024 13:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-numeric-values-in-results-with-reference-file-containing/m-p/913116#M359909</guid>
      <dc:creator>Aku</dc:creator>
      <dc:date>2024-01-26T13:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Match numeric values in results with reference file containing string values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-numeric-values-in-results-with-reference-file-containing/m-p/913120#M359911</link>
      <description>&lt;P&gt;Hello&lt;BR /&gt;Based upon your first two datasets &lt;STRONG&gt;results&lt;/STRONG&gt; and&lt;STRONG&gt; reference&lt;/STRONG&gt; the outcome does not appear to be what you have shown.&lt;BR /&gt;However using the sample code you should be able to get the desired result as shown&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data results;
input ID resultA resultB;
datalines;
1 2392 887
2 1587 902
3 2392 234
4 4035 2392
;
run;
data reference;
input num first$ last$;
datalines;
2392 joe bloggs
4035 mary smith
1587 bloggs joe
234 sherlock holmes 
902 john watson
887 benjamin button
;
run;

proc sql;
Select id, cat(Propcase(strip(first)),"-",propcase(Strip(last))) as Name from results a,reference b
where a.resultA=b.num;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The code gives result like this with the given datasets results and reference.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sajid01_0-1706277863218.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92994iEE47D9B92512D413/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sajid01_0-1706277863218.png" alt="Sajid01_0-1706277863218.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2024 14:05:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-numeric-values-in-results-with-reference-file-containing/m-p/913120#M359911</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2024-01-26T14:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: Match numeric values in results with reference file containing string values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-numeric-values-in-results-with-reference-file-containing/m-p/913121#M359912</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442273"&gt;@Epi_Stats&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would probably create a custom format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fmt(drop=first last);
retain fmtname 'ref';
set reference(rename=(num=start));
length label $40;
label=catx('-',first,last);
run;

proc format cntlin=fmt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you may not even need dataset WANT because you can get the same information from the existing RESULTS dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=results;
format res: ref.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Creating dataset WANT is not much work either:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=_:);
set results(rename=(resultA=_A resultB=_B));
length resultA resultB $200;
resultA=put(_A, ref.);
resultB=put(_B, ref.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jan 2024 14:08:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-numeric-values-in-results-with-reference-file-containing/m-p/913121#M359912</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-01-26T14:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: Match numeric values in results with reference file containing string values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-numeric-values-in-results-with-reference-file-containing/m-p/913125#M359916</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Very clever to treat the reference file as a format - I had not thought of this!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2024 14:47:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-numeric-values-in-results-with-reference-file-containing/m-p/913125#M359916</guid>
      <dc:creator>Epi_Stats</dc:creator>
      <dc:date>2024-01-26T14:47:57Z</dc:date>
    </item>
  </channel>
</rss>

