<?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: Is there a SAS function similar to an Xlookup? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/785004#M250497</link>
    <description>&lt;P&gt;&lt;SPAN&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;Any idea on how to get these results using the same data sets?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1.&lt;/SPAN&gt; &lt;SPAN&gt;Determine the number of trips that start and end at the same station.&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2.&lt;/SPAN&gt; &lt;SPAN&gt;Find the average trip duration for trips that start and end at the same station.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Dec 2021 20:14:04 GMT</pubDate>
    <dc:creator>zoromakoni</dc:creator>
    <dc:date>2021-12-08T20:14:04Z</dc:date>
    <item>
      <title>Is there a SAS function similar to an Xlookup?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/784394#M250311</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;0&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;I am working on a project that involves two separate CSV files. The first data set, "Trips" has seven columns, with a trip_id, bike_id, duration, from_station_id, to_station_id, capacity and usertype. User type is the only character values, the rest are numerical. The second csv file has station_id and station_name. The objective is to merge the files in some way that will input the station name from the second csv file into the "from" and "to" station sections in the first, based on station id. I know that this would be extremely easy in excel with an xlookup, but I am wondering the correct way to approach this in SAS.&lt;/P&gt;&lt;P&gt;I am using the SAS university edition (the free online one) if that makes any difference. Our code so far is as follows:&lt;/P&gt;&lt;P&gt;'''data DivvyTrips; infile '/home/u59304398/sasuser.v94/DivvyTrips.csv' dsd; input trip_id bikeid tripduration from_station_id to_station_id capacity usertype $; title "Trips"; run;&lt;/P&gt;&lt;P&gt;data DivvyStations; infile '/home/u59304398/sasuser.v94/Divvy_Stations.csv' dsd; input station_id station_name $; title "Stations"; run;'''&lt;/P&gt;&lt;P&gt;All this does is import the data. I do not think a merge with a sort will work because we need both from and to station names.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 06 Dec 2021 20:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/784394#M250311</guid>
      <dc:creator>camryndastrup</dc:creator>
      <dc:date>2021-12-06T20:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function similar to an Xlookup?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/784395#M250312</link>
      <description>Merge and sort is exactly the right answer, exactly how depends on your data. Please make a small useable example with fake data if necessary if you need help with code. &lt;BR /&gt;&lt;BR /&gt;FYI - it really helps if you format your posts to be legible.</description>
      <pubDate>Mon, 06 Dec 2021 21:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/784395#M250312</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-06T21:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function similar to an Xlookup?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/784398#M250314</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are several ways of doing this using a merge with data step or PROC SQL or with a hash table lookup (also in data step).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you do not even have to join the data sets if you use the powerful concept of a SAS format.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The second csv file has station_id and station_name&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Create a format that "translates" station_id into station_name like is done here:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;SAS 9.4 / Viya 3.5&lt;BR /&gt;Base SAS Procedures Guide&lt;BR /&gt;FORMAT Procedure&lt;BR /&gt;&lt;STRONG&gt;Example 13: Creating a Format from a CNTLIN= Data Set&lt;/STRONG&gt;&lt;BR /&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n1e19y6lrektafn1kj6nbvhus59w.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n1e19y6lrektafn1kj6nbvhus59w.htm&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Just apply&amp;nbsp;the newly created format to&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;from_station_id and to_station_id&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;in the first dataset.&lt;BR /&gt;While the internal value(s) stays the same (station_id) it is now displayed as station_name.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Koen&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 21:11:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/784398#M250314</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-12-06T21:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function similar to an Xlookup?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/784399#M250315</link>
      <description>&lt;P&gt;I have attached the data we are using.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data DivvyTrips;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;infile '/home/u59304398/sasuser.v94/DivvyTrips.csv' dsd;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;input trip_id&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;bikeid&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;tripduration&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;from_station_id&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;to_station_id&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;capacity&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;usertype $;&lt;BR /&gt;title "Trips";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data DivvyStations;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;infile '/home/u59304398/sasuser.v94/Divvy_Stations.csv' dsd;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;input station_id&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;station_name $;&lt;BR /&gt;title "Stations";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what we have so far, simply to import the data into the online SAS. The files I imported did not have labels in the first row, I only added them to the data files I am uploading for clarity.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if that is enough information, and I appreciate your help!&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 21:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/784399#M250315</guid>
      <dc:creator>camryndastrup</dc:creator>
      <dc:date>2021-12-06T21:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function similar to an Xlookup?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/784400#M250316</link>
      <description>I will try that!</description>
      <pubDate>Mon, 06 Dec 2021 21:14:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/784400#M250316</guid>
      <dc:creator>camryndastrup</dc:creator>
      <dc:date>2021-12-06T21:14:54Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function similar to an Xlookup?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/784410#M250324</link>
      <description>&lt;P&gt;Don't truncate you station names to 8 characters.&lt;/P&gt;
&lt;P&gt;Use the station table to define a format and then use the format to display the station ids as their names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DivvyStations;
     infile 'c:\downloads\Divvy_Stations.csv' dsd firstobs=2;
     input station_id station_name :$40.;
run;

data format;
   fmtname='STATION';
   set divvystations;
   rename station_id=start station_name=label;
run;
proc format cntlin=format;
run;

proc print data=divvytrips(obs=10) width=min;
  format from_station_id to_station_id station.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 927px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66443iC13070E4D32933A4/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 22:18:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/784410#M250324</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-06T22:18:54Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function similar to an Xlookup?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/785004#M250497</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;Any idea on how to get these results using the same data sets?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1.&lt;/SPAN&gt; &lt;SPAN&gt;Determine the number of trips that start and end at the same station.&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2.&lt;/SPAN&gt; &lt;SPAN&gt;Find the average trip duration for trips that start and end at the same station.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2021 20:14:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/785004#M250497</guid>
      <dc:creator>zoromakoni</dc:creator>
      <dc:date>2021-12-08T20:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function similar to an Xlookup?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/785008#M250498</link>
      <description>&lt;BR /&gt;&lt;BR /&gt;proc means data=divvytrips N MEAN;&lt;BR /&gt;where from_station_id = to_station_id;&lt;BR /&gt;var tripduration;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 08 Dec 2021 20:25:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/785008#M250498</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-08T20:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a SAS function similar to an Xlookup?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/785014#M250499</link>
      <description>&lt;P&gt;Thanks that helps&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2021 20:45:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-a-SAS-function-similar-to-an-Xlookup/m-p/785014#M250499</guid>
      <dc:creator>zoromakoni</dc:creator>
      <dc:date>2021-12-08T20:45:44Z</dc:date>
    </item>
  </channel>
</rss>

