<?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: Generalizing a macro to include the data set and its variables in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Generalizing-a-macro-to-include-the-data-set-and-its-variables/m-p/218446#M5331</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are on the right path for datafile, it should work as shown. Just remember that you may need to include the library and set: datafile=mylib.thisdataset but that will work. Generally I will make a separate Library reference but that is a style choice as much as anything. Though if you are referencing many sets in the same library it may be more efficient.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Add a parameter varlist to the macro call:&lt;/P&gt;&lt;P&gt;&lt;STRONG style="background: white; color: navy; font-family: 'Courier New'; font-size: 10pt;"&gt;%MACRO&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt; sortandprint(datafile=, sortseq=, sortvar=, varlist=);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;and call as&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="background: white; color: navy; font-family: 'Courier New'; font-size: 10pt;"&gt;%&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;sortandprint(datafile=datasetname, sortseq=, sortvar=, varlist= thisvar thatvar anothervar);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;NOTE that the comma delimits the parameters. So the list shouldn't contain commas in general.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;If you need at some point to pass the varlist with commas then use&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;varlist=%str( thisvar, thatvar, anothervar) in the macro call.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 22 May 2015 17:05:19 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2015-05-22T17:05:19Z</dc:date>
    <item>
      <title>Generalizing a macro to include the data set and its variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Generalizing-a-macro-to-include-the-data-set-and-its-variables/m-p/218445#M5330</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;suppose I have the following macro:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;%MACRO&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; sortandprint(sortseq=, sortvar=);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;PROC SORT DATA = models;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; BY &amp;amp;sortseq &amp;amp;sortvar;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;PROC PRINT DATA = models NOOBS;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; TITLE &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'Current Models'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; TITLE2 &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"Sorted by &amp;amp;sortseq &amp;amp;sortvar"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; VAR Model Class Frame Price;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;RUN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;%MEND&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; sortandprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;Is it possible to generalize this macro even further in the following ways:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;1) also create a macro variable for the name of the data file so that have the following:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; font-size: 13.3333330154419px;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;%MACRO&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background: white;"&gt; sortandprint(datafile=, sortseq=, sortvar=);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background: white;"&gt;PROC SORT DATA = &amp;amp;&lt;SPAN style="color: #000000; font-family: 'Courier New'; font-size: 13.3333330154419px; background-color: #ffffff;"&gt;datafile&lt;/SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background: white;"&gt;2) put all the variables of the datfile into a list so that get something like the following:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background: white;"&gt;var &amp;amp;varlist&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New'; color: black; background: white;"&gt;thank you!&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 May 2015 16:57:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Generalizing-a-macro-to-include-the-data-set-and-its-variables/m-p/218445#M5330</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2015-05-22T16:57:29Z</dc:date>
    </item>
    <item>
      <title>Re: Generalizing a macro to include the data set and its variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Generalizing-a-macro-to-include-the-data-set-and-its-variables/m-p/218446#M5331</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are on the right path for datafile, it should work as shown. Just remember that you may need to include the library and set: datafile=mylib.thisdataset but that will work. Generally I will make a separate Library reference but that is a style choice as much as anything. Though if you are referencing many sets in the same library it may be more efficient.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Add a parameter varlist to the macro call:&lt;/P&gt;&lt;P&gt;&lt;STRONG style="background: white; color: navy; font-family: 'Courier New'; font-size: 10pt;"&gt;%MACRO&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt; sortandprint(datafile=, sortseq=, sortvar=, varlist=);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;and call as&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="background: white; color: navy; font-family: 'Courier New'; font-size: 10pt;"&gt;%&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;sortandprint(datafile=datasetname, sortseq=, sortvar=, varlist= thisvar thatvar anothervar);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;NOTE that the comma delimits the parameters. So the list shouldn't contain commas in general.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;If you need at some point to pass the varlist with commas then use&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; font-size: 10pt;"&gt;varlist=%str( thisvar, thatvar, anothervar) in the macro call.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 May 2015 17:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Generalizing-a-macro-to-include-the-data-set-and-its-variables/m-p/218446#M5331</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-05-22T17:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: Generalizing a macro to include the data set and its variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Generalizing-a-macro-to-include-the-data-set-and-its-variables/m-p/218447#M5332</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1) Yes - try your code&lt;/P&gt;&lt;P&gt;2) Yes - but also look at _all_ _numeric_ variable lists. You also don't need to specify Var in proc print and then it prints everything. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 May 2015 23:30:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Generalizing-a-macro-to-include-the-data-set-and-its-variables/m-p/218447#M5332</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-05-22T23:30:03Z</dc:date>
    </item>
  </channel>
</rss>

