<?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: add log message to dataset in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572495#M12338</link>
    <description>Post the log/actual error. Where the error occurs is noted in the log and makes it much easier to debug. You should also be using MPRINT/SYMBOLGEN to help you debug.</description>
    <pubDate>Wed, 10 Jul 2019 19:42:34 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-07-10T19:42:34Z</dc:date>
    <item>
      <title>add log message to dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572464#M12326</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I was wondering if I could add log message to a dataset&lt;/P&gt;&lt;P&gt;I'am using the macro VarExists(ds,var) as an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro VarExist(ds,var);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;%local rc dsid result;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;%let dsid = %sysfunc(open(&amp;amp;ds));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;%if %sysfunc(varnum(&amp;amp;dsid, &amp;amp;var)) &amp;gt; 0 %then %do;&lt;/P&gt;&lt;P&gt;%let result = 1;&lt;/P&gt;&lt;P&gt;%put Note: Var &amp;amp;var exists in %ds;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%else %do;&lt;/P&gt;&lt;P&gt;%let result = 0;&lt;/P&gt;&lt;P&gt;%put Note: Var &amp;amp;var not exists in &amp;amp;ds;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let rc = %sysfunc(close(&amp;amp;dsid));&lt;/P&gt;&lt;P&gt;&amp;amp;result&lt;/P&gt;&lt;P&gt;%mend VarExists;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%varexist(sashelpclass, aaa);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have little knowledge in SAS, but what I want (I will write a pseudo code below) is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if result = 1:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; do nothing&lt;/P&gt;&lt;P&gt;if result = 0:&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;input message $;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;Note: Var &amp;amp;var not exists in &amp;amp;ds&amp;nbsp; \* here &amp;amp;var and &amp;amp;ds will be the macro input*\&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so there will be a final dataset that looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;message&lt;/P&gt;&lt;P&gt;var aaa not exists in sashelp.class&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to do this? Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 18:15:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572464#M12326</guid>
      <dc:creator>laiguanyu001</dc:creator>
      <dc:date>2019-07-10T18:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: add log message to dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572483#M12330</link>
      <description>There is a way, but honestly, its not a good idea. &lt;BR /&gt;&lt;BR /&gt;What are you trying to do overall? PROC COMPARE will compare data sets to ensure variables are the same and formats/lengths and print a report for example. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 10 Jul 2019 19:06:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572483#M12330</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-10T19:06:41Z</dc:date>
    </item>
    <item>
      <title>Re: add log message to dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572484#M12331</link>
      <description>&lt;P&gt;If you want a data set with a single record and variable it is likely easier to just assign a value to the variable instead of using data lines and you can't actually use macro variables in data lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
   message = "Note: Var &amp;amp;var. does not exist in &amp;amp;ds.";
run;&lt;/PRE&gt;
&lt;P&gt;If you want to ADD this, as a different record to an existing data set then 1) make a temporary data set as above and 2) append the temporary set to the final data set. Your requirement isn't quite clear on the desired output.&lt;/P&gt;
&lt;P&gt;The data step would go in the same place as the %let result =0; in the example code to create that WANT data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you might describe what problem you are actually attempting to solve has this seems to be&amp;nbsp;pretty convoluted approach to getting such a message into a data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are searching for a bunch of variables in multiple sets there are much more efficient ways to do this, especially if you have&amp;nbsp;the data set names (and libraries involved) and variable names in a data set.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 20:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572484#M12331</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-10T20:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: add log message to dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572485#M12332</link>
      <description>&lt;P&gt;I'm trying to output all error messages in one big dataset... For this specific task I'm trying to find if certain variable exists. if it doesn't, output the error message to a data set. There are also other tasks like this too, And I'm just trying to create one report that contains all the errors.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't think proc compare will work? because you are comparing variables in different datasets, but I'm trying to do here is find if a variable exists in one data set.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 19:13:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572485#M12332</guid>
      <dc:creator>laiguanyu001</dc:creator>
      <dc:date>2019-07-10T19:13:21Z</dc:date>
    </item>
    <item>
      <title>Re: add log message to dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572486#M12333</link>
      <description>Here's an example I wrote a while back, to compare two data sets and generate a short data set/report on the variables.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/e0b98c4627aa31a567e5" target="_blank"&gt;https://gist.github.com/statgeek/e0b98c4627aa31a567e5&lt;/A&gt;</description>
      <pubDate>Wed, 10 Jul 2019 19:14:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572486#M12333</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-10T19:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: add log message to dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572490#M12335</link>
      <description>Then I would make a specific set of codes that does each task and creates an error message within that proc that appends to a master error table. This is a method I've used before but it's pretty manual. If you're using SAS EG or Studio, all the errors or notes are easily navigable so this seems redundant as well.</description>
      <pubDate>Wed, 10 Jul 2019 19:15:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572490#M12335</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-10T19:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: add log message to dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572493#M12337</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro varexist(ds,var);
%local rc dsid result;
%let dsid = %sysfunc(open(&amp;amp;ds));
%if %sysfunc(varnum(&amp;amp;dsid,&amp;amp;var))&amp;gt;0 %then %do;
%let result = 1;
%end;
%else %do;
%let result = 0;
%end;

%if &amp;amp;result = 0 %then %do;
data error_data;
message = "Note: Var &amp;amp;var. does not exist in &amp;amp;ds.";
run;
%end;

%mend;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried this and get :statement is not valid or it is used out of proper order&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 19:39:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572493#M12337</guid>
      <dc:creator>laiguanyu001</dc:creator>
      <dc:date>2019-07-10T19:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: add log message to dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572495#M12338</link>
      <description>Post the log/actual error. Where the error occurs is noted in the log and makes it much easier to debug. You should also be using MPRINT/SYMBOLGEN to help you debug.</description>
      <pubDate>Wed, 10 Jul 2019 19:42:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572495#M12338</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-10T19:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: add log message to dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572507#M12341</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/279765"&gt;@laiguanyu001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro varexist(ds,var);
%local rc dsid result;
%let dsid = %sysfunc(open(&amp;amp;ds));
%if %sysfunc(varnum(&amp;amp;dsid,&amp;amp;var))&amp;gt;0 %then %do;
%let result = 1;
%end;
%else %do;
%let result = 0;
%end;

%if &amp;amp;result = 0 %then %do;
data error_data;
message = "Note: Var &amp;amp;var. does not exist in &amp;amp;ds.";
run;
%end;

%mend;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I tried this and get :statement is not valid or it is used out of proper order&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Copy from the LOG AFTER using OPTIONS MPRINT SYMBOLGEN&amp;nbsp;with the 1) code defining the macro, 2) the call you made to the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Worked for me:&lt;/P&gt;
&lt;PRE&gt;74   %macro varexist(ds,var);
75   %local rc dsid result;
76   %let dsid = %sysfunc(open(&amp;amp;ds));
77   %if %sysfunc(varnum(&amp;amp;dsid,&amp;amp;var))&amp;gt;0 %then %do;
78   %let result = 1;
79   %end;
80   %else %do;
81   %let result = 0;
82   %end;
83
84   %if &amp;amp;result = 0 %then %do;
85   data error_data;
86   message = "Note: Var &amp;amp;var. does not exist in &amp;amp;ds.";
87   run;
88   %end;
89
90   %mend;
NOTE: The macro VAREXIST completed compilation without errors.
      39 instructions 848 bytes.
91
92   %varexist(ds=sashelp.class, var=pdq);

NOTE: The data set USER.ERROR_DATA has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds







&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jul 2019 20:20:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/add-log-message-to-dataset/m-p/572507#M12341</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-10T20:20:36Z</dc:date>
    </item>
  </channel>
</rss>

