<?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: how to use put with %let together in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-put-with-let-together/m-p/894832#M353478</link>
    <description>&lt;P&gt;You can use single quotes to mask the macro triggers.&amp;nbsp; Then you can use double quotes inside the single quotes when you need to have quote marks in your generated code, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file log;

  put 'proc datasets lib = work kill memtype = data nolist;' ;
  put 'quit;' ;

  put '%include "setup.sas";' ;
  put '%let studyid= &amp;amp;study.;' ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you're interested in learning the macro language, you may want to consider developing this as a macro.&amp;nbsp; SAS macros are another option for generating SAS code.&amp;nbsp; But plenty of folks like to use PUT statements as you are doing.&amp;nbsp; The macro approach for this code might look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro setup(study=) ;
  %local studyid ; *maybe global, depending on what you want;
  proc datasets lib = work kill memtype = data nolist;
  quit;
  %include "setup.sas" ;
  %let studyid=&amp;amp;study ;&lt;BR /&gt;  %*more stuff here;
%mend setup ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 18 Sep 2023 17:50:21 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2023-09-18T17:50:21Z</dc:date>
    <item>
      <title>how to use put with %let together</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-put-with-let-together/m-p/894823#M353474</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create&amp;nbsp; a sas file using put statement and run into some issue with %let. Could some one take a look and see how I can fix it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;filename outfile "&amp;amp;pgmname..sas" lrecl=2000;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;file outfile;&lt;/P&gt;&lt;P&gt;put 'proc datasets lib = work kill memtype = data nolist;';&lt;BR /&gt;put 'quit;';&lt;/P&gt;&lt;P&gt;put "%include 'setup.sas';";&lt;BR /&gt;put "%let studyid= &amp;amp;study. ;";&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;if I set study= "101", forsome reason, I can not show "%let studyid=101;" in my outfile, but just an " there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What should I do in order to show my "%let ..."?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2023 17:13:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-put-with-let-together/m-p/894823#M353474</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2023-09-18T17:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: how to use put with %let together</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-put-with-let-together/m-p/894828#M353476</link>
      <description>&lt;P&gt;You need to mask % and &amp;amp; so they are not resolved as macro characters with macro meanings. They need to be interpreted by your program as plain text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put "%nrstr(%let studyid= &amp;amp;study.) ;";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2023 17:29:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-put-with-let-together/m-p/894828#M353476</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-18T17:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to use put with %let together</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-put-with-let-together/m-p/894831#M353477</link>
      <description>&lt;P&gt;I can see that you know about single quotes as masking content from the macro parser.&amp;nbsp; But you want both "%include" and single quotes as part of the PUT text.&amp;nbsp; And&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;'s suggestion of %nrstr shows how the macro developers created a macro function to address the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you can still use single quotes for the %include and double quotes for the single-quoted text, by dividing the elements of the text appropriately:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  put '%include '  "'setup.sas';" ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Sep 2023 17:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-put-with-let-together/m-p/894831#M353477</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-09-18T17:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: how to use put with %let together</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-put-with-let-together/m-p/894832#M353478</link>
      <description>&lt;P&gt;You can use single quotes to mask the macro triggers.&amp;nbsp; Then you can use double quotes inside the single quotes when you need to have quote marks in your generated code, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file log;

  put 'proc datasets lib = work kill memtype = data nolist;' ;
  put 'quit;' ;

  put '%include "setup.sas";' ;
  put '%let studyid= &amp;amp;study.;' ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you're interested in learning the macro language, you may want to consider developing this as a macro.&amp;nbsp; SAS macros are another option for generating SAS code.&amp;nbsp; But plenty of folks like to use PUT statements as you are doing.&amp;nbsp; The macro approach for this code might look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro setup(study=) ;
  %local studyid ; *maybe global, depending on what you want;
  proc datasets lib = work kill memtype = data nolist;
  quit;
  %include "setup.sas" ;
  %let studyid=&amp;amp;study ;&lt;BR /&gt;  %*more stuff here;
%mend setup ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Sep 2023 17:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-put-with-let-together/m-p/894832#M353478</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-09-18T17:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to use put with %let together</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-put-with-let-together/m-p/894836#M353479</link>
      <description>&lt;P&gt;Which value of STUDY to you want to assign to STUDY_ID?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The value that exists when the data step with the PUT statements runs?&lt;/STRONG&gt;&amp;nbsp; If so then that is almost what you are currently doing. Just don't use double quotes around the %LET so that the macro processor will not try to interpret it before the DATA step runs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put '%let studyid=' "&amp;amp;study.;";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Or the value that exists AFTER the %INCLUDE statement runs?&lt;/STRONG&gt;&amp;nbsp; If the latter then use single quotes so that the PUT statement will write out &amp;amp;STUDY instead of the value of STUDY.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put '%let studyid= &amp;amp;study. ;';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2023 18:31:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-put-with-let-together/m-p/894836#M353479</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-18T18:31:43Z</dc:date>
    </item>
  </channel>
</rss>

