<?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: Reading in with LIBNAME XLSX Q in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717412#M221855</link>
    <description>Thanks to both of you. This makes sense.&lt;BR /&gt;&lt;BR /&gt;Two final questions.&lt;BR /&gt;&lt;BR /&gt;What would be the point of sorting BY multiple variables? (multiple variables in BY statement)&lt;BR /&gt;&lt;BR /&gt;And second, what happens if you try to sort on a variable that is already sorted?&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Sun, 07 Feb 2021 16:14:00 GMT</pubDate>
    <dc:creator>edasdfasdfasdfa</dc:creator>
    <dc:date>2021-02-07T16:14:00Z</dc:date>
    <item>
      <title>Reading in with LIBNAME XLSX Q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717404#M221847</link>
      <description>&lt;P&gt;options validvarname=any;&lt;/P&gt;&lt;P&gt;LIBNAME xl XLSX '/home/john/B.xlsx';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm using the above to read in an Excel file with 2 sheets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want these two sheets of info to be combined based on an ID&amp;nbsp; (both have ID columns).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But pretty sure the ID's and maybe even Dates would have to first be sorted? So, first, how can that be done with multiple sheets using libname xlsx?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason I ask is because unlike something like proc import where I would have a dataset to sort, here I don't.&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;</description>
      <pubDate>Sun, 07 Feb 2021 15:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717404#M221847</guid>
      <dc:creator>edasdfasdfasdfa</dc:creator>
      <dc:date>2021-02-07T15:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in with LIBNAME XLSX Q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717405#M221848</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/201537"&gt;@edasdfasdfasdfa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;options validvarname=any;&lt;/P&gt;
&lt;P&gt;LIBNAME xl XLSX '/home/john/B.xlsx';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm using the above to read in an Excel file with 2 sheets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want these two sheets of info to be combined based on an ID&amp;nbsp; (both have ID columns).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What do you mean by "combined"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;But pretty sure the ID's and maybe even Dates would have to first be sorted? So, first, how can that be done with multiple sheets using libname xlsx?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason I ask is because unlike something like proc import where I would have a dataset to sort, here I don't.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;LIBNAME does give you data sets to work with. You sort them using PROC SORT and OUT= to create a new sorted data set. Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=xl.data1 out=data1;
    by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 15:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717405#M221848</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-02-07T15:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in with LIBNAME XLSX Q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717406#M221849</link>
      <description>&lt;P&gt;Hi Paige,&lt;/P&gt;&lt;P&gt;Thanks for the quick response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When you say '&lt;SPAN&gt;LIBNAME does give you data sets to work with.' ..I do see the two individual Sheets as members.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So would I sort each sheet individually but use the same out= dataset name? does that work?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;By combine..I meant that all the observations for a certain ID would be in one row..as opposed to multiple.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 15:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717406#M221849</guid>
      <dc:creator>edasdfasdfasdfa</dc:creator>
      <dc:date>2021-02-07T15:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in with LIBNAME XLSX Q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717408#M221851</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=xl.data1 out=data1;
by id;
run;
proc sort data=xl.data2 out=data2;
by id;
run;
data want;
    merge data1 data2;
    by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 07 Feb 2021 15:39:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717408#M221851</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-02-07T15:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in with LIBNAME XLSX Q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717410#M221853</link>
      <description>&lt;P&gt;Once you have defined a libref with the XLSX engine you can reference each sheet as if it was a dataset.&amp;nbsp; So if you had sheets named SHEET1 and SHEET2 your could MERGE them by ID with code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME xl XLSX '/home/john/B.xlsx';
data want;
  merge xl.sheet1 xl.sheet2;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the data in the sheets are not sorted by ID then you will need to sort them first and then merge the sorted versions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=xl.sheet1 out=sheet1_sorted;
  by id;
run;
proc sort data=xl.sheet2 out=sheet2_sorted;
  by id;
run;
data want ;
  merge sheet1_sorted sheet2_sorted;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 07 Feb 2021 15:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717410#M221853</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-07T15:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in with LIBNAME XLSX Q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717412#M221855</link>
      <description>Thanks to both of you. This makes sense.&lt;BR /&gt;&lt;BR /&gt;Two final questions.&lt;BR /&gt;&lt;BR /&gt;What would be the point of sorting BY multiple variables? (multiple variables in BY statement)&lt;BR /&gt;&lt;BR /&gt;And second, what happens if you try to sort on a variable that is already sorted?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 07 Feb 2021 16:14:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717412#M221855</guid>
      <dc:creator>edasdfasdfasdfa</dc:creator>
      <dc:date>2021-02-07T16:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in with LIBNAME XLSX Q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717413#M221856</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/201537"&gt;@edasdfasdfasdfa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;Two final questions.&lt;BR /&gt;&lt;BR /&gt;What would be the point of sorting BY multiple variables? (multiple variables in BY statement)&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It sorts by multiple variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;And second, what happens if you try to sort on a variable that is already sorted?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Nothing.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 16:16:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717413#M221856</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-02-07T16:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in with LIBNAME XLSX Q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717415#M221858</link>
      <description>&lt;P&gt;You sort by multiple BY variables to establish the order that you want repeating values of the earlier variables to appear.&amp;nbsp; For example you might sort by subject id and visit date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=measurements;
  by id date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So now the subjects are ordered and the multiple observations for the same subject are ordered chronologically.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 16:21:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717415#M221858</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-07T16:21:12Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in with LIBNAME XLSX Q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717419#M221862</link>
      <description>&lt;P&gt;You can't read more than one sheet at a time, so stacking the sheets with &lt;CODE&gt;SET xl.sheet1 xl.sheet2;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;will cause an ERROR:.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Copy each sheet to WORK, and stack them as desired.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;proc sort data=sashelp.class out=class;
  by sex name;
run;

ods excel file='class.xlsx' options(sheet_name='#byval1');

options nobyline;
ods noresults;

proc print noobs data=class;
  by sex;
run;

ods excel close;

libname xl excel 'class.xlsx';

* File in user ERROR: ;

data want;
  set 
    indsname = sheetname
    xl.'F$'n
    xl.'M$'n
  ;

  by name;

  sex = sheetname;
run;

data one; set xl.'F$'n; sex='F';
data two; set xl.'M$'n; sex='M';

data want;
  set one two indsname=sheetname;
  by name;
run;

libname xl;&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 07 Feb 2021 16:34:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717419#M221862</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2021-02-07T16:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in with LIBNAME XLSX Q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717420#M221863</link>
      <description>&lt;P&gt;Thanks, Tom.&lt;/P&gt;&lt;P&gt;I like the output the way I have it now...where ID is in order so I can easily see debit/credit over the course of different days..&lt;/P&gt;&lt;P&gt;but is there some kind of merging/joining/combining..that would enable you to only have one row for each ID regardless of how many different transactions on different days there were? or would you handle that just by using some filtering?&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 16:35:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717420#M221863</guid>
      <dc:creator>edasdfasdfasdfa</dc:creator>
      <dc:date>2021-02-07T16:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Reading in with LIBNAME XLSX Q</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717421#M221864</link>
      <description>&lt;P&gt;I don't get such an error, Richard.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 16:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-in-with-LIBNAME-XLSX-Q/m-p/717421#M221864</guid>
      <dc:creator>edasdfasdfasdfa</dc:creator>
      <dc:date>2021-02-07T16:36:56Z</dc:date>
    </item>
  </channel>
</rss>

