<?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: scan in the proc sql in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/scan-in-the-proc-sql/m-p/665058#M22896</link>
    <description>&lt;P&gt;When you have problems with macros, place this command at the start of your program and then run the program again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen mlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then, show us the ENTIRE log for this step, not just the error message. We need to see the code, the NOTEs, the WARNINGs and the ERRORs. Paste the log as text into the box that appears when you click the &amp;lt;/&amp;gt; icon. THis makes the log more legible and readable. DO NOT SKIP THIS STEP.&lt;/P&gt;</description>
    <pubDate>Thu, 25 Jun 2020 16:15:10 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-06-25T16:15:10Z</dc:date>
    <item>
      <title>scan in the proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/scan-in-the-proc-sql/m-p/665053#M22895</link>
      <description>&lt;P&gt;Hi SAS users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need help with the below error (wrong output). I am trying to build the select variables based on the fld values that are being passed in the parameter. I tried alias but still i am unable to get the right values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;fld has 2 values with pipe delimeter and i am looking for SQL to build the below way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select&amp;nbsp; distinct ID , NAME from&amp;nbsp;from &amp;amp;input_dataset&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CODE is as below -&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro util_macro_insert (fld=,Input_Dataset=,Var_Util= , Output_Dataset=);&lt;BR /&gt;&lt;BR /&gt;%let fld_cnt = %sysevalf(%sysfunc(COUNTC(&amp;amp;fld,|))+1);&lt;BR /&gt;%put &amp;amp;=fld_cnt;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table &amp;amp;Output_Dataset. as&lt;BR /&gt;select distinct %DO i=1 %to &amp;amp;fld_cnt; &lt;BR /&gt;%if &amp;amp;i = 1 %then %do; trim(%scan(&amp;amp;fld,&amp;amp;i,|))&amp;nbsp; &amp;nbsp;%end; &lt;BR /&gt;%if &amp;amp;i &amp;gt; 1 %then %do ; ,trim(%scan(&amp;amp;fld,&amp;amp;i,|)) %end;&lt;BR /&gt;%END; &lt;BR /&gt;from &amp;amp;input_dataset&lt;BR /&gt;;&lt;BR /&gt;Quit;&lt;BR /&gt;&lt;BR /&gt;%mend util_macro_insert;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%util_macro_insert (fld=ID | name,Input_Dataset=test1,Var_Util=NBR, Output_dataset =output );&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR :&amp;nbsp; I am getting _TEMA001 and _TEMA002&amp;nbsp; instead of ID &amp;amp; NAME.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Ana&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 16:01:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/scan-in-the-proc-sql/m-p/665053#M22895</guid>
      <dc:creator>SASAna</dc:creator>
      <dc:date>2020-06-25T16:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: scan in the proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/scan-in-the-proc-sql/m-p/665058#M22896</link>
      <description>&lt;P&gt;When you have problems with macros, place this command at the start of your program and then run the program again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen mlogic;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then, show us the ENTIRE log for this step, not just the error message. We need to see the code, the NOTEs, the WARNINGs and the ERRORs. Paste the log as text into the box that appears when you click the &amp;lt;/&amp;gt; icon. THis makes the log more legible and readable. DO NOT SKIP THIS STEP.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 16:15:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/scan-in-the-proc-sql/m-p/665058#M22896</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-06-25T16:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: scan in the proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/scan-in-the-proc-sql/m-p/665066#M22897</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; &amp;nbsp; : I am generating the output but the field names are coming as random SAS variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the log&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable OUTPUT_DATASET resolves to FWAE_UTIL_CLAIMS&lt;BR /&gt;SYMBOLGEN: Macro variable FLD_CNT resolves to 2&lt;BR /&gt;MLOGIC(UTIL_MACRO_INSERT): %DO loop beginning; index variable I; start value is 1; stop value is 2; by value is 1. &lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 1&lt;BR /&gt;MLOGIC(UTIL_MACRO_INSERT): %IF condition &amp;amp;i = 1 is TRUE&lt;BR /&gt;SYMBOLGEN: Macro variable FLD resolves to ID|NAME&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 1&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 1&lt;BR /&gt;MLOGIC(UTIL_MACRO_INSERT): %IF condition &amp;amp;i &amp;gt; 1 is FALSE&lt;BR /&gt;MLOGIC(UTIL_MACRO_INSERT): %DO loop index variable I is now 2; loop will iterate again.&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 2&lt;BR /&gt;MLOGIC(UTIL_MACRO_INSERT): %IF condition &amp;amp;i = 1 is FALSE&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 2&lt;BR /&gt;MLOGIC(UTIL_MACRO_INSERT): %IF condition &amp;amp;i &amp;gt; 1 is TRUE&lt;BR /&gt;SYMBOLGEN: Macro variable FLD resolves to ID|NAME&lt;BR /&gt;SYMBOLGEN: Macro variable I resolves to 2&lt;BR /&gt;MLOGIC(UTIL_MACRO_INSERT): %DO loop index variable I is now 3; loop will not iterate again.&lt;BR /&gt;SYMBOLGEN: Macro variable INPUT_DATASET resolves to test1&lt;BR /&gt;MPRINT(UTIL_MACRO_INSERT): create table FWAE_UTIL_CLAIMS as select distinct trim(ID) ,trim(NAME) from test1 ;&lt;BR /&gt;NOTE: Table WORK.FWAE_UTIL_CLAIMS created, with 97 rows and 2 columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tinyMceEditorSASAna_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tinyMceEditorSASAna_1" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 16:21:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/scan-in-the-proc-sql/m-p/665066#M22897</guid>
      <dc:creator>SASAna</dc:creator>
      <dc:date>2020-06-25T16:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: scan in the proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/scan-in-the-proc-sql/m-p/665067#M22898</link>
      <description>&lt;P&gt;Pretty much any time you use a function in SQL you are in effect creating a new variable and if you do not provide a name for the variable the SAS will create one based on the position of the variable creating code.&lt;/P&gt;
&lt;P&gt;Consider these two example data sets.&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table example1 as
   select distinct trim(sex)
   from sashelp.class
   ;
quit;


proc sql;
   create table example2 as
   select distinct trim(sex) as sex
   from sashelp.class
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;The second code shows the fix you need for your example.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 16:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/scan-in-the-proc-sql/m-p/665067#M22898</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-25T16:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: scan in the proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/scan-in-the-proc-sql/m-p/665068#M22899</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;fld has 2 values with pipe delimeter and i am looking for SQL to build the below way.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know if this is possible with your code, but to avoid this entirely could you pass in a comma delimited string instead? Use %STR() to mask the comma's when you pass the parameter to the macro. Or instead convert the pipes to comma using TRANSLATE? Also, this macro is basically just PROC FREQ, as presented, but I'm assuming you're simplifying things here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 

%macro util_macro_insert (fld=,Input_Dataset=,Var_Util= , Output_Dataset=);

proc sql;
create table &amp;amp;Output_Dataset. as
select distinct &amp;amp;fld
from &amp;amp;input_dataset
;
Quit;

%mend util_macro_insert;


%util_macro_insert (fld= %str(ID, name) ,Input_Dataset=test1,Var_Util=NBR, Output_dataset =output );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or the translate option:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro util_macro_insert (fld=,Input_Dataset=,Var_Util= , Output_Dataset=);

%let fld = %sysfunc(translate(&amp;amp;fld, ',', '|'));
%put &amp;amp;fld.;

proc sql;
create table &amp;amp;Output_Dataset. as
select distinct &amp;amp;fld
from &amp;amp;input_dataset
;
Quit;

%mend util_macro_insert;


%util_macro_insert (fld= age|sex ,Input_Dataset=sashelp.class,Var_Util=NBR, Output_dataset  =want );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: Adding in the PROC FREQ version because...&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro util_macro_insert (fld=,Input_Dataset=,Var_Util= , Output_Dataset=);

%let fld = %sysfunc(translate(&amp;amp;fld, '*', '|'));

proc freq data=&amp;amp;input_dataset NOPRINT;
table &amp;amp;fld / out = &amp;amp;output_dataset (drop = count percent);
run;

%mend util_macro_insert;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jun 2020 16:28:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/scan-in-the-proc-sql/m-p/665068#M22899</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-25T16:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: scan in the proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/scan-in-the-proc-sql/m-p/665069#M22900</link>
      <description>&lt;P&gt;We need to see the ENTIRE log for this section of code, not selected parts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Paste the log as text into the box that appears when you click the &amp;lt;/&amp;gt; icon. DO NOT SKIP THIS STEP.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 16:26:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/scan-in-the-proc-sql/m-p/665069#M22900</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-06-25T16:26:09Z</dc:date>
    </item>
    <item>
      <title>Re: scan in the proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/scan-in-the-proc-sql/m-p/665071#M22901</link>
      <description>&lt;BR /&gt;Thank you so much. I was coding it in complex way .Answer is such a easy way &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;Ana</description>
      <pubDate>Thu, 25 Jun 2020 16:33:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/scan-in-the-proc-sql/m-p/665071#M22901</guid>
      <dc:creator>SASAna</dc:creator>
      <dc:date>2020-06-25T16:33:44Z</dc:date>
    </item>
  </channel>
</rss>

