<?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: DSNAME function not working in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DSNAME-function-not-working/m-p/921289#M362810</link>
    <description>&lt;P&gt;Most likely cause would be you don't have a dataset named sasuser.houses, or you have run the code more than once.&amp;nbsp; If you run the code twice (without closing the dataset you have opened), the value of DSID will be 2 (if the dataset is present).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest adding a %PUT statement to check the value of DSID.&amp;nbsp; 0 means the dataset was not found and could not be opened.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also I would use the macro variable DSID inside the DSNAME function instead of hardcoding the value 1.&amp;nbsp; So try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsid=%sysfunc(open(sashelp.class));
%put dsid=&amp;amp;dsid ;
%put The current open data set is %sysfunc(dsname(&amp;amp;dsid));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And that should work. Then try changing from sashelp.class to sasuser.houses and see if it still works.&lt;/P&gt;</description>
    <pubDate>Thu, 21 Mar 2024 13:27:36 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2024-03-21T13:27:36Z</dc:date>
    <item>
      <title>DSNAME function not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DSNAME-function-not-working/m-p/921281#M362809</link>
      <description>&lt;P&gt;%let dsid=%sysfunc(open(sasuser.houses));&lt;BR /&gt;%put The current open data set&lt;BR /&gt;is %sysfunc(dsname(1));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just copied this from the sas documentation site, but it is throwing error. I tried using datastep method as well, rather than macro function , but it is still the same. Below is the log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;338 %let dsid=%sysfunc(open(sasuser.houses));&lt;BR /&gt;339 %put The current open data set&lt;BR /&gt;340 is %sysfunc(dsname(1));&lt;BR /&gt;WARNING: Argument 1 to function DSNAME referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.&lt;BR /&gt;The current open data set is&lt;BR /&gt;341&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do anyone know why so?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 13:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DSNAME-function-not-working/m-p/921281#M362809</guid>
      <dc:creator>angird1990</dc:creator>
      <dc:date>2024-03-21T13:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: DSNAME function not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DSNAME-function-not-working/m-p/921289#M362810</link>
      <description>&lt;P&gt;Most likely cause would be you don't have a dataset named sasuser.houses, or you have run the code more than once.&amp;nbsp; If you run the code twice (without closing the dataset you have opened), the value of DSID will be 2 (if the dataset is present).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest adding a %PUT statement to check the value of DSID.&amp;nbsp; 0 means the dataset was not found and could not be opened.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also I would use the macro variable DSID inside the DSNAME function instead of hardcoding the value 1.&amp;nbsp; So try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsid=%sysfunc(open(sashelp.class));
%put dsid=&amp;amp;dsid ;
%put The current open data set is %sysfunc(dsname(&amp;amp;dsid));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And that should work. Then try changing from sashelp.class to sasuser.houses and see if it still works.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 13:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DSNAME-function-not-working/m-p/921289#M362810</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-03-21T13:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: DSNAME function not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DSNAME-function-not-working/m-p/921772#M362983</link>
      <description>&lt;P&gt;Thank you. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;You're right!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2024 05:39:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DSNAME-function-not-working/m-p/921772#M362983</guid>
      <dc:creator>angird1990</dc:creator>
      <dc:date>2024-03-26T05:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: DSNAME function not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DSNAME-function-not-working/m-p/921773#M362984</link>
      <description>&lt;OL class="lia-list-style-type-upper-roman"&gt;
&lt;LI&gt;instead of a literal, use the result of the OPEN function&lt;/LI&gt;
&lt;LI&gt;whenever you use OPEN, also issue a CLOSE call in the same submit; make your code clean up after itself&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;II. is also true for all similar operations (FOPEN/FCLOSE, DOPEN/DCLOSE and so on)&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2024 10:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DSNAME-function-not-working/m-p/921773#M362984</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-03-26T10:25:10Z</dc:date>
    </item>
  </channel>
</rss>

