<?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: OBS AND OUTOBS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/OBS-AND-OUTOBS/m-p/564455#M158334</link>
    <description>&lt;P&gt;Try this, Might be you are looking for this.&lt;/P&gt;&lt;P&gt;Note : you can sum logic same like this , and can use want table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
x='10'; output;
x='11';output;
y=11;output;
run;

%macro calculation;
proc sql;
select count(*) into:cnt_obs from have;
quit;
%put &amp;amp;cnt_obs;

proc contents data= have out=structure(keep=name type);
run;

proc sql;
select count(*) into:cnt_var from structure;
quit;
%put &amp;amp;cnt_var;

data want;
numobs=&amp;amp;cnt_obs;
numbervar=&amp;amp;cnt_var;
run;

%mend calculation;

%calculation;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 07 Jun 2019 13:09:05 GMT</pubDate>
    <dc:creator>Riteshdell</dc:creator>
    <dc:date>2019-06-07T13:09:05Z</dc:date>
    <item>
      <title>OBS AND OUTOBS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/OBS-AND-OUTOBS/m-p/564433#M158322</link>
      <description>&lt;P&gt;Good morning,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to know how to capture the number of observations and variables in a sas dataset and also summing a numeric vari called tran_amount all in one report. I know proc contents will give me the number obs and var. I need something like numobs=, numbervar= and suum_tran_amount = all in one report.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-mauri&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 11:21:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/OBS-AND-OUTOBS/m-p/564433#M158322</guid>
      <dc:creator>mauri0623</dc:creator>
      <dc:date>2019-06-07T11:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: OBS AND OUTOBS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/OBS-AND-OUTOBS/m-p/564451#M158331</link>
      <description>&lt;P&gt;what have you tried? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to create a data-step version of your data&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/help/faqpage/faq-category-id/posting#posting" target="_blank"&gt;https://communities.sas.com/t5/help/faqpage/faq-category-id/posting#posting&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;How to Add attachments&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/Community-Memo/Adding-attachments-to-your-communities-posts/ba-p/464767" target="_blank"&gt;https://communities.sas.com/t5/Community-Memo/Adding-attachments-to-your-communities-posts/ba-p/464767&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 12:52:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/OBS-AND-OUTOBS/m-p/564451#M158331</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-06-07T12:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: OBS AND OUTOBS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/OBS-AND-OUTOBS/m-p/564454#M158333</link>
      <description>&lt;P&gt;Have you tried using PROC SQL? This will do what you need quickly and easily.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 13:01:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/OBS-AND-OUTOBS/m-p/564454#M158333</guid>
      <dc:creator>Karen_Horton</dc:creator>
      <dc:date>2019-06-07T13:01:58Z</dc:date>
    </item>
    <item>
      <title>Re: OBS AND OUTOBS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/OBS-AND-OUTOBS/m-p/564455#M158334</link>
      <description>&lt;P&gt;Try this, Might be you are looking for this.&lt;/P&gt;&lt;P&gt;Note : you can sum logic same like this , and can use want table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
x='10'; output;
x='11';output;
y=11;output;
run;

%macro calculation;
proc sql;
select count(*) into:cnt_obs from have;
quit;
%put &amp;amp;cnt_obs;

proc contents data= have out=structure(keep=name type);
run;

proc sql;
select count(*) into:cnt_var from structure;
quit;
%put &amp;amp;cnt_var;

data want;
numobs=&amp;amp;cnt_obs;
numbervar=&amp;amp;cnt_var;
run;

%mend calculation;

%calculation;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Jun 2019 13:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/OBS-AND-OUTOBS/m-p/564455#M158334</guid>
      <dc:creator>Riteshdell</dc:creator>
      <dc:date>2019-06-07T13:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: OBS AND OUTOBS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/OBS-AND-OUTOBS/m-p/564456#M158335</link>
      <description>&lt;P&gt;Since the first two are summaries of metadata about the data set and the last is a summary about the data in the dataset your will need to use two separate steps (or subqueries) to get that information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's say you have the dataset HAVE.&amp;nbsp;&amp;nbsp;Since you already know how to get the first two let's assume you have already created that in a dataset named CONTENT_SUMMARY.&amp;nbsp; Now you just need to get the SUM of your variable and combine them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have ;
  var tran_amount;
  output out=data_summary sum=sum_tran_amount;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And then combine the two.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set content_summary;
  set data_summary;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Jun 2019 13:13:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/OBS-AND-OUTOBS/m-p/564456#M158335</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-07T13:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: OBS AND OUTOBS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/OBS-AND-OUTOBS/m-p/564466#M158342</link>
      <description>&lt;P&gt;I always use the dictionary tables versus using proc contents.&amp;nbsp; I use this a lot for creating data dictionaries for the programs.&lt;/P&gt;&lt;P&gt;Something like this:&lt;/P&gt;&lt;P&gt;Proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;select *&lt;/P&gt;&lt;P&gt;&amp;nbsp;from dictionary.columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;where libname= 'WORK' /*is always uppercase*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; and memname='DATASETNAME' /* is always upcase */&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that select * from dictionary.columns tell you about the columns in the table like length, type, format, informat, etc. while select * from dictionary.tables gives the number of logical obs (nlobs) and the number of columns/variables in the table/dataset/database table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 13:46:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/OBS-AND-OUTOBS/m-p/564466#M158342</guid>
      <dc:creator>Suzanne_McCoy</dc:creator>
      <dc:date>2019-06-07T13:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: OBS AND OUTOBS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/OBS-AND-OUTOBS/m-p/564468#M158343</link>
      <description>&lt;P&gt;I wasn't sure exactly how you wanted the specific items you requested to be accessed so I put the values into Macro Variables that can be referenced however you want. I build the logic in a macro statement but it could just have easily been a simple data step. I went with the macro&amp;nbsp;statement instead so that the data step could easily be used across multiple datasets throughout a process if needed (so long as the values from one run are used prior to the values of a separate tables run otherwise the macro values will overwrite one another).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO TableDtls(TableName, InputSumVar, OutputCumSumVar);
	DATA _NULL_;
		DSID = OPEN("&amp;amp;TableName.");
			Vars = ATTRN(DSID,"NVARS");
			CALL SYMPUTX('Total_Variables',Vars, 'G');            /* put variable count in macro variable */
			CALL SYMPUTX('Total_Observations',&amp;amp;SQLOOPS., 'G');            /* put variable count in macro variable */
		RC = CLOSE(DSID); 
		SET &amp;amp;TableName.;
		FORMAT &amp;amp;OutputCumSumVar. 5.1;
		RETAIN &amp;amp;OutputCumSumVar.;
		IF _N_=1 THEN &amp;amp;OutputCumSumVar. = &amp;amp;InputSumVar.;
		ELSE &amp;amp;OutputCumSumVar. = (&amp;amp;OutputCumSumVar. + &amp;amp;InputSumVar.);
		CALL SYMPUTX("&amp;amp;OutputCumSumVar",&amp;amp;OutputCumSumVar., 'G');            /* put variable count in macro variable */
	RUN;

	%PUT &amp;amp;=Total_Variables;
	%PUT &amp;amp;=Total_Observations;
	%PUT &amp;amp;OutputCumSumVar.= &amp;amp;&amp;amp;&amp;amp;OutputCumSumVar.;
%MEND TableDtls;

%TableDtls(SASHELP.class, Weight, Sum_Weight);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So when you call the TableDtls Macro, you will provide 3 pieces of information:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - First, the name of the table that you want to get the observation count, variable count, and summary details&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - Second, the name of the variable that you want the summary details&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - Third, the name that you want for the new macro&amp;nbsp;variable that will resolve to&amp;nbsp;the sum of the previously supplied variable&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The three new Macro variables generated&amp;nbsp;will resolve with these values:&lt;/P&gt;&lt;PRE&gt;TOTAL_VARIABLES=5
TOTAL_OBSERVATIONS=19
Sum_Weight= 1900.5&lt;/PRE&gt;&lt;P&gt;Confirming that the SASHELP.Class table contains:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; - 5 variables&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; - 19 total observations&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; - And&amp;nbsp;the sum of the 19 weight values equals 1900.5.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the data in the SASHELP.Class table for review:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Obs     Name     Sex     Age     Height     Weight 
1       Alfred   M        14       69.0      112.5 
2       Alice    F        13       56.5       84.0 
3       Barbara  F        13       65.3       98.0 
4       Carol    F        14       62.8      102.5 
5       Henry    M        14       63.5      102.5 
6       James    M        12       57.3       83.0 
7       Jane     F        12       59.8       84.5 
8       Janet    F        15       62.5      112.5 
9       Jeffrey  M        13       62.5       84.0 
10      John     M        12       59.0       99.5 
11      Joyce    F        11       51.3       50.5 
12      Judy     F        14       64.3       90.0 
13      Louise   F        12       56.3       77.0 
14      Mary     F        15       66.5      112.0 
15      Philip   M        16       72.0      150.0 
16      Robert   M        12       64.8      128.0 
17      Ronald   M        15       67.0      133.0 
18      Thomas   M        11       57.5       85.0 
19      William  M        15       66.5      112.0&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 13:52:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/OBS-AND-OUTOBS/m-p/564468#M158343</guid>
      <dc:creator>tsap</dc:creator>
      <dc:date>2019-06-07T13:52:17Z</dc:date>
    </item>
  </channel>
</rss>

