<?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 macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475671#M122323</link>
    <description>&lt;P&gt;how to create a macros that counts patient number and observation number for each dataset ?&lt;/P&gt;&lt;P&gt;For eg. this is what i made&amp;nbsp; , but it doesnt work&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro willthismacrowork(yn) ;
	
	proc sql ;
		select count(enrolid) , count(obs) 
		from &amp;amp;syslast. ;
	quit ;

	%put yn ;
%mend willthismacrowork(yn=yes) ;
%willthismacrowork ;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 05 Jul 2018 15:17:30 GMT</pubDate>
    <dc:creator>manya92</dc:creator>
    <dc:date>2018-07-05T15:17:30Z</dc:date>
    <item>
      <title>macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475671#M122323</link>
      <description>&lt;P&gt;how to create a macros that counts patient number and observation number for each dataset ?&lt;/P&gt;&lt;P&gt;For eg. this is what i made&amp;nbsp; , but it doesnt work&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro willthismacrowork(yn) ;
	
	proc sql ;
		select count(enrolid) , count(obs) 
		from &amp;amp;syslast. ;
	quit ;

	%put yn ;
%mend willthismacrowork(yn=yes) ;
%willthismacrowork ;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475671#M122323</guid>
      <dc:creator>manya92</dc:creator>
      <dc:date>2018-07-05T15:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475675#M122324</link>
      <description>&lt;P&gt;Can you provide a sample of an INPUT data and your expected OUTPUT sample explaining your requirement plz?&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475675#M122324</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-05T15:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475679#M122326</link>
      <description>&lt;P&gt;For eg, i have different datasets , some of whihc are one row per patient and some are multiple rows per patient. Now&amp;nbsp; instead of writing the whole code like :-&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql ;
select count(enrolid), count(obs)
from have ;
quit ;


&lt;/PRE&gt;&lt;P&gt;i wish to make a MACROS that i have to just call to print this for me each time i want to see the number instead of having to type all that code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:21:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475679#M122326</guid>
      <dc:creator>manya92</dc:creator>
      <dc:date>2018-07-05T15:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475681#M122327</link>
      <description>&lt;PRE&gt;%macro willthismacrowork(ds=);
	
  proc sql ;
    select count(enrolid), 
           count(obs) 
    from &amp;amp;ds.;
  quit;

%mend willthismacrowork;
%willthismacrowork;&lt;/PRE&gt;
&lt;P&gt;I would suggest that if you are starting to develop general code you start by documenting it rather than coding.&amp;nbsp; Using &amp;amp;syslast. is a pretty bad idea, what if you want to do this several times on different datasets for a start?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Posting "&lt;SPAN&gt;but it doesnt work" does not tell us anything, what doesn't work, logs with errors, incorrect logic, etc.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:22:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475681#M122327</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-07-05T15:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475682#M122328</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;but it doesnt work&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Why do you say that? Explain! Provide information! Show us the SASLOG (use the {i} icon and paste relevant portions of the SASLOG into the box that appears).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:22:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475682#M122328</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-05T15:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475685#M122329</link>
      <description>&lt;P&gt;This question is making less sense.&amp;nbsp; You want to create a macro to print out number of observations in a dataset?&amp;nbsp; Look at the look, when you use a dataset it prints how many observations are in the dataset.&amp;nbsp; Seems to me to just be creating work for no purpose.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:25:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475685#M122329</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-07-05T15:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475687#M122330</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/208127"&gt;@manya92&lt;/a&gt;&amp;nbsp; The community would like to see a nice data sample . Just words will only delay and will keep going back and forth.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you after this?&lt;/P&gt;&lt;P&gt;The sample i use is sashelp.class dataset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select count(*) as gender_count,( select count(*) from sashelp.class) as obs_count
from sashelp.class
group by sex;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:27:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475687#M122330</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-05T15:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475690#M122333</link>
      <description>&lt;P&gt;I made a MACROS earlier like below :&lt;/P&gt;&lt;PRE&gt;%macro print ;
	
	proc print data = &amp;amp;syslast. (obs=10) ;
	run ;
%mend print ;
%print ;&lt;/PRE&gt;&lt;P&gt;So whenever i want to print a dataset i simply CALL THE MACROS&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;BR /&gt;%print;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:29:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475690#M122333</guid>
      <dc:creator>manya92</dc:creator>
      <dc:date>2018-07-05T15:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475695#M122335</link>
      <description>&lt;P&gt;Please read this in continuation with the previous text&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now i wish to create a similar macros that will print the number of distinct patients for me and the numebr of observations so i can see if my dataset is unique p by patient id or not&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For eg. something like this :-&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro obs ;

proc sql ;
select count(enrolid), count(obs)
from &amp;amp;syslast.
;
quit ;

%mend obs ;
%obs; &lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:32:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475695#M122335</guid>
      <dc:creator>manya92</dc:creator>
      <dc:date>2018-07-05T15:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475699#M122336</link>
      <description>&lt;P&gt;You are running before you can walk in this and your other post.&amp;nbsp; Forget macros, learn how to do things in Base SAS - this is the programming language.&amp;nbsp; Avoid using &amp;amp;syslast., I understand it is used on one of the SAS systems, but personally I find it very bad coding, and if you go into general code then you could end up with all kinds of issues.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you not know if your dataset is distinct?&amp;nbsp; Did you not create it?&amp;nbsp; Obs is printed to the log each time.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:35:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475699#M122336</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-07-05T15:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475700#M122337</link>
      <description>&lt;P&gt;The macro will run, but&amp;nbsp;I don't think the SQL query is doing what you really want.&lt;/P&gt;
&lt;P&gt;Try this instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro patient_obs() ;
%global nobs npatients ;
proc sql noprint;
  select
         count(distinct enrolid) format=32.
       , count(*) format=32.
    into 
         :npatients trimmed 
       , :nobs trimmed
  from &amp;amp;syslast. 
  ;
quit ;
%put Dataset &amp;amp;syslast has &amp;amp;nobs observations and &amp;amp;npatients patients ;
%mend patient_obs;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:53:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475700#M122337</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-05T15:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475710#M122344</link>
      <description>&lt;P&gt;So when i run this MACROS theres no error but when i call this MACROS to give me the number of patients and observations it gives me this error :-&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         %patient_obs ;
 ERROR: The following columns were not found in the contributing tables: N.
 NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE SQL used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 Dataset WORK._01_ELIG                         has  observations and  patients
 74         
 75         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 88         &lt;/PRE&gt;&lt;P&gt;Also, this is what is the code for which the above error appeared :-&lt;/P&gt;&lt;PRE&gt;data derived._01_cohort1 ;
	set _01_age ;
run ;/*12316*/

%patient_obs ;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:51:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475710#M122344</guid>
      <dc:creator>manya92</dc:creator>
      <dc:date>2018-07-05T15:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475713#M122345</link>
      <description>&lt;P&gt;I am not sure if SYSLAST is remember across submissions when using SAS/Studio or Enterprise Guide.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also there is no reference to N in the macro I posted, so you are perhaps running something different?&lt;/P&gt;
&lt;P&gt;You can turn on the MPRINT option to see the SAS code that the macro has generated.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:54:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475713#M122345</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-05T15:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475715#M122346</link>
      <description>&lt;P&gt;Even when i wrote this :- , it says OBS variable not found in &amp;amp;syslast.&lt;/P&gt;&lt;PRE&gt;%macro patient_obs() ;&lt;BR /&gt;%global nobs npatients ;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt; select&lt;BR /&gt; count(distinct enrolid) format=32.&lt;BR /&gt; , count(obs) format=32.&lt;BR /&gt; into &lt;BR /&gt; :npatients trimmed &lt;BR /&gt; , :nobs trimmed&lt;BR /&gt; from &amp;amp;syslast. &lt;BR /&gt; ;&lt;BR /&gt;quit ;&lt;BR /&gt;%put Dataset &amp;amp;syslast. has &amp;amp;nobs. observations and &amp;amp;npatients. patients ;&lt;BR /&gt;%mend patient_obs;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:58:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475715#M122346</guid>
      <dc:creator>manya92</dc:creator>
      <dc:date>2018-07-05T15:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475716#M122347</link>
      <description>&lt;P&gt;If you want to make the macro more flexible add parameters.&amp;nbsp; You can include logic to add a default value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can have SAS add the default value for you if you make the parameters non-positional.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro patient_obs(dsn=&amp;amp;syslast);
....
  from &amp;amp;dsn 
....
%mend ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can add your own logic.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro patient_obs(dsnt);
%if 0=%length(&amp;amp;dsn) %then %let dsn=&amp;amp;syslast;
%if not %sysfunc(exist(&amp;amp;dsn)) %then %do;
  %put &amp;amp;=dsn not found.;
%end;
....
  from &amp;amp;dsn 
....
%mend ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475716#M122347</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-05T15:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475717#M122348</link>
      <description>&lt;P&gt;Do not use a variable name there.&amp;nbsp; Use either * or 1.&amp;nbsp; I updated the earlier post.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 16:00:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475717#M122348</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-05T16:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475734#M122354</link>
      <description>&lt;P&gt;Thank You&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 17:11:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475734#M122354</guid>
      <dc:creator>manya92</dc:creator>
      <dc:date>2018-07-05T17:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475742#M122358</link>
      <description>&lt;P&gt;in this code&amp;nbsp; :- what is INTO:npatients trimmed nobs trimmed for ? i dont know what trimmed means in this case&lt;/P&gt;&lt;PRE&gt;%macro patient_obs() ;
%global nobs npatients ;
proc sql noprint;
  select
         count(enrolid) format=32.
       , count(N) format=32.
    into 
         :npatients trimmed 
       , :nobs trimmed
  from &amp;amp;syslast. 
  ;
quit ;
%put Dataset &amp;amp;syslast. has &amp;amp;nobs. observations and &amp;amp;npatients. patients ;
%mend patient_obs;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Jul 2018 17:27:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475742#M122358</guid>
      <dc:creator>manya92</dc:creator>
      <dc:date>2018-07-05T17:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475757#M122363</link>
      <description>&lt;P&gt;Apparently the new SAS 9.4 documentation is defective.&lt;/P&gt;
&lt;P&gt;Look at the SAs 9.3 documentation instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/sqlproc/63043/HTML/default/viewer.htm#n1tupenuhmu1j0n19d3curl9igt4.htm" target="_self"&gt;INTO clause&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 18:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros/m-p/475757#M122363</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-05T18:03:41Z</dc:date>
    </item>
  </channel>
</rss>

