<?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: Find Unmatched Double Quote in Macro Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-Unmatched-Double-Quote-in-Macro-Variable/m-p/954507#M372776</link>
    <description>&lt;P&gt;In that case I recommend adding the quotes so you can use the password more easily in code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Say your user prompt create the macro variable PASSWORD. Your program can then use this data step to generate a single quoted string with the password into either the name macro variable (or a different one if you want).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symputx('password',quote(symget('password'),"'"));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the rest of your code can use the macro variable to pass the password to the places where it is needed.&amp;nbsp; For example in making a database connection:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname myora oracle path=myserver user=&amp;amp;userid pass=&amp;amp;password ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 23 Dec 2024 16:58:42 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-12-23T16:58:42Z</dc:date>
    <item>
      <title>Find Unmatched Double Quote in Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Unmatched-Double-Quote-in-Macro-Variable/m-p/954427#M372743</link>
      <description>&lt;P&gt;Hi there - first time posting.&amp;nbsp; Hoping you can help me!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created a program that prompts for a password.&amp;nbsp; I need to identify if the password contains any double quotes ("), matched or unmatched.&amp;nbsp; Whether that be removing them and comparing a before and after length or finding the location of the " and if the result is &amp;gt;0 then it one exists.&amp;nbsp; The catch is I also need to ensure that any predefined SAS macro variables that could inadvertently end up in the password do not resolve.&amp;nbsp; Here are a couple of things I have tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Password Entered:&amp;nbsp;&amp;nbsp;&amp;nbsp; Abc"2025&amp;amp;sysdate&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;OPTIONS MPRINT SYMBOLGEN;

*Entered into Prompt;
*_NOLOG_pw = Abc"2024&amp;amp;sysdate;

%PUT _NOLOG_pw = &amp;amp;_NOLOG_PW;

%LET NOLOG = %SUPERQ(_NOLOG_PW);
%PUT NOLOG - &amp;amp;NOLOG.;

%LET NOLOG_NRSTR = %NRSTR(&amp;amp;NOLOG);
%PUT NOLOG_NRSTR = &amp;amp;NOLOG_NRSTR;


%let nolog_find = %sysfunc(find(&amp;amp;NOLOG_NRSTR, %str(%"))); *Resolves to 0;
%put &amp;amp;nolog_find;

data _null_;
	TRANWORD = translate(&amp;amp;NOLOG,%str( ),%str(%")); * Results in error;
	call symput('NOLOG_TRANWORD',TRANWORD);
RUN;

%PUT NOLOG_TRANWORD = &amp;amp;NOLOG_TRANWORD;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="terminal,monaco"&gt;Here is the log:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="terminal,monaco"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-12-21 160518.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103328i0A7460B8A72C817D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-12-21 160518.png" alt="Screenshot 2024-12-21 160518.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-12-21 160626.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103329i41C35FFDAE1E2B76/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-12-21 160626.png" alt="Screenshot 2024-12-21 160626.png" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="terminal,monaco"&gt;Any help you can provide will be greatly appreciated.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="terminal,monaco"&gt;Thanks!&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Dec 2024 23:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Unmatched-Double-Quote-in-Macro-Variable/m-p/954427#M372743</guid>
      <dc:creator>Abt1075</dc:creator>
      <dc:date>2024-12-21T23:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: Find Unmatched Double Quote in Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Unmatched-Double-Quote-in-Macro-Variable/m-p/954430#M372744</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _NOLOG_pw =%bquote( Abc"2024&amp;amp;sysdate );  /* %let _NOLOG_pw =%bquote( &amp;amp;_NOLOG_pw );  */
%PUT _NOLOG_pw = &amp;amp;_NOLOG_PW ;

%let nolog_find = %sysfunc(find(&amp;amp;_NOLOG_pw, %str(%")));
%put &amp;amp;=nolog_find;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;1    %let _NOLOG_pw =%bquote( Abc"2024&amp;amp;sysdate );  /* %let _NOLOG_pw =%bquote( &amp;amp;_NOLOG_pw );  */
2    %PUT _NOLOG_pw = &amp;amp;_NOLOG_PW ;
&lt;STRONG&gt;_NOLOG_pw =  Abc"202422DEC24&lt;/STRONG&gt;
3
4
5
6
7    %let nolog_find = %sysfunc(find(&amp;amp;_NOLOG_pw, %str(%")));
8    %put &amp;amp;=nolog_find;
&lt;STRONG&gt;NOLOG_FIND=5
&lt;/STRONG&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Dec 2024 02:04:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Unmatched-Double-Quote-in-Macro-Variable/m-p/954430#M372744</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-12-22T02:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: Find Unmatched Double Quote in Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Unmatched-Double-Quote-in-Macro-Variable/m-p/954493#M372772</link>
      <description>&lt;P&gt;I suspect you are having trouble because you are using %SYSFUNC() to call SAS functions.&amp;nbsp; That causes trouble with strings that have macro triggers as %SYSFUNC() has to convert the macro strings to actual strings to pass to the SAS functions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But from your description there SAS macro already has a function for this, %INDEX().&amp;nbsp; So there is no need to get %SYSFUNC() involved and so no need to worry about how it handles macro triggers like &amp;amp; and %.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First let's make a macro variable with that string.&amp;nbsp; Easier way is using a DATA step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symputx('_NOLOG_pw', 'Abc"2024&amp;amp;sysdate');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now we can find the location of the first " character like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let location = %index(%superq(_nolog_pw),%str(%"));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;But what is the goal here?&lt;/STRONG&gt;&amp;nbsp; Is the goal to convert the macro variable into something that you can use more easily?&amp;nbsp; Since everywhere you need to reference a password you can normally use single quotes around the value (like in my data step above) then just add the single quotes to the macro variable.&amp;nbsp; That can easily be done with a data step.&amp;nbsp; Use SYMGET() to retrieve the value without worrying about macro quoting.&amp;nbsp; Use QUOTE() to add the quotes. Use CALL SYMPUTX() to store the result back into a macro variable.&amp;nbsp; Perhaps the same one?&lt;/P&gt;
&lt;PRE&gt;1    data _null_;
2      call symputx('_NOLOG_pw', 'Abc"2024&amp;amp;sysdate');
3    run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


4
5    data _null_;
6      call symputx('_NOLOG_pw',quote(symget('_NOLOG_PW'),"'"));
7    run;

NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


8
9    %put &amp;amp;=_nolog_pw;
_NOLOG_PW='Abc"2024&amp;amp;sysdate'
&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Do you want the &amp;amp;SYSDATE to evaluate?&amp;nbsp;&lt;/STRONG&gt; If so then use %BQUOTE() to handle the potentially unbalanced quotes.&lt;/P&gt;
&lt;PRE&gt;1    data _null_;
2      call symputx('_NOLOG_pw', 'Abc"2024&amp;amp;sysdate');
3    run;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


4
5    %put Raw value is |%superq(_nolog_pw)|;
Raw value is |Abc"2024&amp;amp;sysdate|
6    %put Value after evaluation is |%bquote(&amp;amp;_nolog_pw)|;
Value after evaluation is |Abc"202423DEC24|
&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Dec 2024 15:07:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Unmatched-Double-Quote-in-Macro-Variable/m-p/954493#M372772</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-23T15:07:49Z</dc:date>
    </item>
    <item>
      <title>Re: Find Unmatched Double Quote in Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Unmatched-Double-Quote-in-Macro-Variable/m-p/954495#M372773</link>
      <description>&lt;P&gt;how about this way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Entered into Prompt;
data _null_;
call symputx('_NOLOG_PW','Abc"2024&amp;amp;sysdate');
run;
/*_NOLOG_pw = Abc"2024&amp;amp;sysdate;*/


/* CODE */
%put %sysfunc(dosubl(%str( 
data _null_;
  x = resolve(symget('_NOLOG_PW'));
  put x=;
  call symputx('_NOLOG_PW', x,'G');
  call symputx('_location', find(x,'"'),'G');
run;
)));

%PUT _NOLOG_pw = %superq(_NOLOG_PW);

%put &amp;amp;=_location.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 23 Dec 2024 15:23:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Unmatched-Double-Quote-in-Macro-Variable/m-p/954495#M372773</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-12-23T15:23:40Z</dc:date>
    </item>
    <item>
      <title>Re: Find Unmatched Double Quote in Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Unmatched-Double-Quote-in-Macro-Variable/m-p/954496#M372774</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _NOLOG_pw =%bquote( Abc"2024&amp;amp;sysdate );  /* %let _NOLOG_pw =%bquote( &amp;amp;_NOLOG_pw );  */
%PUT _NOLOG_pw = &amp;amp;_NOLOG_PW ;

%let nolog_find = %sysfunc(find(&amp;amp;_NOLOG_pw, %str(%")));
%put &amp;amp;=nolog_find;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;1    %let _NOLOG_pw =%bquote( Abc"2024&amp;amp;sysdate );  /* %let _NOLOG_pw =%bquote( &amp;amp;_NOLOG_pw );  */
2    %PUT _NOLOG_pw = &amp;amp;_NOLOG_PW ;
&lt;STRONG&gt;_NOLOG_pw =  Abc"202422DEC24&lt;/STRONG&gt;
3
4
5
6
7    %let nolog_find = %sysfunc(find(&amp;amp;_NOLOG_pw, %str(%")));
8    %put &amp;amp;=nolog_find;
&lt;STRONG&gt;NOLOG_FIND=5
&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Two issues.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First the double quote is the fourth character, not the the fifth. You added spaces before and after the value in your %BQUOTE() call so your answer is off by 1.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Second why use FIND? INDEX works fine for this problem. And SAS macro has a built in %INDEX() function that can be used.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Dec 2024 15:29:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Unmatched-Double-Quote-in-Macro-Variable/m-p/954496#M372774</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-23T15:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: Find Unmatched Double Quote in Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Unmatched-Double-Quote-in-Macro-Variable/m-p/954500#M372775</link>
      <description>&lt;P&gt;Thank you for your quick response Tom.&amp;nbsp; The goal is to keep the users password in tact, meaning to not resolve &amp;amp;sysdate.&amp;nbsp; I used that as an example of a possible issue since users should be able to use a '&amp;amp;' in their password.&amp;nbsp; The %index worked perfectly.&amp;nbsp; Thank you so much.&amp;nbsp; The first screenshot below is what comes through from the prompt, and the second screenshot is the log for the %index.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-12-23 083713.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103342iD06AC74D0BDCB411/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-12-23 083713.png" alt="Screenshot 2024-12-23 083713.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-12-23 083750.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103341i0E4251455CDEAA65/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-12-23 083750.png" alt="Screenshot 2024-12-23 083750.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Dec 2024 15:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Unmatched-Double-Quote-in-Macro-Variable/m-p/954500#M372775</guid>
      <dc:creator>Abt1075</dc:creator>
      <dc:date>2024-12-23T15:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: Find Unmatched Double Quote in Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Unmatched-Double-Quote-in-Macro-Variable/m-p/954507#M372776</link>
      <description>&lt;P&gt;In that case I recommend adding the quotes so you can use the password more easily in code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Say your user prompt create the macro variable PASSWORD. Your program can then use this data step to generate a single quoted string with the password into either the name macro variable (or a different one if you want).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symputx('password',quote(symget('password'),"'"));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the rest of your code can use the macro variable to pass the password to the places where it is needed.&amp;nbsp; For example in making a database connection:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname myora oracle path=myserver user=&amp;amp;userid pass=&amp;amp;password ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Dec 2024 16:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Unmatched-Double-Quote-in-Macro-Variable/m-p/954507#M372776</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-23T16:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Find Unmatched Double Quote in Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-Unmatched-Double-Quote-in-Macro-Variable/m-p/954529#M372777</link>
      <description>Tom,&lt;BR /&gt;"%BQUOTE() call so your answer is off by 1."&lt;BR /&gt;Yes. Should remove the head blanks. Here I just want show an example.&lt;BR /&gt;%let _NOLOG_pw =%bquote(Abc"2024&amp;amp;sysdate);&lt;BR /&gt;&lt;BR /&gt;"Second why use FIND? INDEX works fine "&lt;BR /&gt;That code is not written by me ,it is from OP , I just use OP's code, since I don't know why OP wrote this.</description>
      <pubDate>Tue, 24 Dec 2024 01:18:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-Unmatched-Double-Quote-in-Macro-Variable/m-p/954529#M372777</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-12-24T01:18:22Z</dc:date>
    </item>
  </channel>
</rss>

