<?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: Adding New Missing Observation in Data Step in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/446241#M28867</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro abc() ;

	/*1. Create Data Sets within the defined timeframe*/
	proc sql;
		create table MV_MISSING_VALUE AS
		select *
		from pankaj.mv_yield_detail_mm
		where "&amp;amp;mindate."dt &amp;lt;= PROCESSED_DTTM &amp;lt;="&amp;amp;maxdate."dt;
	quit;
	
	/*2. Generate the table with proc sql with varname and type*/
	
	proc sql ;
		create table varlist_1 as
		select name, type from  dictionary.columns
		where libname = upcase("work") and memname = upcase("MV_MISSING_VALUE");
	quit;

	/*3. Looping through the Variables and checking the Data Type */
 	%do I=1 %to %sysfunc(countw(&amp;amp;varlist)); 
	 		%let var = %scan(&amp;amp;varlist, &amp;amp;I);
			%put &amp;amp;var.;

			/*3.1To check the Data Type for all the varibales in varlist. */		
			proc sql noprint;
				select type into: t separated by ' ' from varlist_1
				where name="&amp;amp;var.";
			quit;
			%put check=&amp;amp;t.;


	/*4. Formatting with Character Values*/
	%if &amp;amp;t=char %then %do;
		/*length var $32;*/
		proc freq data=work.MV_MISSING_VALUE;
			format &amp;amp;var. $missfmt.; /* apply format for the duration of this PROC */
			tables &amp;amp;var. / missing missprint nocum  out= Final_Output_&amp;amp;var ;
		run;

		/*DATA Step for Filtering Only Missing Values in a separate Tables*/
		DATA Final_Output_&amp;amp;var;
			set Final_Output_&amp;amp;var;
			where put (&amp;amp;var., $missfmt.) in ("Missing");
		run;		
	%end; 

	/*5. Formatting with Numeric Format*/
	%else %do;
		proc freq data=work.MV_MISSING_VALUE;
			format &amp;amp;var. missfmt.; /* apply format for the duration of this PROC */
			tables &amp;amp;var. / missing  missprint nocum out= Final_Output_&amp;amp;var ;
		run;
	
		/*DATA Step for Filtering Only Missing Values in a separate Tables*/
		DATA Final_Output_&amp;amp;var;
			set Final_Output_&amp;amp;var;
			where put (&amp;amp;var., missfmt.) in ("Missing");
		run;
		
	%end;

	
	/*6. Add new variable*/
	data Final_Output_&amp;amp;var ; 
			set Final_Output_&amp;amp;var ;
			VARNAME = "&amp;amp;var" ;
			
		run ;


	%end;
%mend;
%abc;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is what I am intended to do in One Macro. I have attached the sample data.&lt;/P&gt;&lt;P&gt;At last, I want the Missing % along with the Variable name.&lt;/P&gt;</description>
    <pubDate>Fri, 16 Mar 2018 16:03:53 GMT</pubDate>
    <dc:creator>narulap</dc:creator>
    <dc:date>2018-03-16T16:03:53Z</dc:date>
    <item>
      <title>Adding New Missing Observation in Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/446157#M28864</link>
      <description>&lt;P&gt;I have multiple Data sets of missing and not missing observations. In some Data sets I have 1 observation of 100% Not Missing and want to add another Observation of MISSING 0%. I am able to do it in numeric variables but for numeric it is adding the observation but with the Not Missing value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May be the issue is with format. that I am adding new observation in place of format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the PROC format for the Character and Numeric Variables for Missing and Not Missing values.&lt;/P&gt;&lt;P&gt;This is the proc format :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
 value $missfmt ' '='Missing' other='Not Missing';
 value  missfmt  . ='Missing' other='Not Missing';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code which I use to add Observation into multiple tables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	proc sql;
			select count("&amp;amp;var.") into: n
			from Final_Output_&amp;amp;var;
	run;
		       %put Nobs=&amp;amp;n.;
		
		%if &amp;amp;n.=1 %then %do;
		   data final_output_&amp;amp;var;
				set final_output_&amp;amp;var end=eof;
				output;
				if eof then do; 
				&amp;amp;var. = "MISSING";
				COUNT=0;
				PERCENT=0;
				output; /* Output new observation */  	
				end;
		  run;					
		%end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It gets Inserted correctly under Numeric Variable but It&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="missing.PNG" style="width: 349px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19223iA8D1E9B7F94AD113/image-size/large?v=v2&amp;amp;px=999" role="button" title="missing.PNG" alt="missing.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But for the Character its is not getting inserted as shown below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="not miss.PNG" style="width: 303px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19224i5844ECF96906F45D/image-size/large?v=v2&amp;amp;px=999" role="button" title="not miss.PNG" alt="not miss.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 13:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/446157#M28864</guid>
      <dc:creator>narulap</dc:creator>
      <dc:date>2018-03-16T13:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Adding New Missing Observation in Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/446159#M28865</link>
      <description>&lt;P&gt;Please provide example data in a data step with datalines.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 13:37:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/446159#M28865</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-16T13:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: Adding New Missing Observation in Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/446209#M28866</link>
      <description>&lt;P&gt;Warning that habitual use of structures like:&lt;BR /&gt;&amp;nbsp;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; final_output_&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; final_output_&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt; end&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;eof&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;will create hard to diagnose data issues because you destroy the old version.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you do not show use of the format or data with the format it is hard to say. I might try&lt;/P&gt;
&lt;PRE&gt;proc format;
 value $missfmt . , '', ' '='Missing' other='Not Missing';
 value  missfmt  . ='Missing' other='Not Missing';
run;&lt;/PRE&gt;
&lt;P&gt;with the format.&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;It looks like you may be doing a lot of work to duplicate the results of one or more SAS report or summarization procedures.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 15:17:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/446209#M28866</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-16T15:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: Adding New Missing Observation in Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/446241#M28867</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro abc() ;

	/*1. Create Data Sets within the defined timeframe*/
	proc sql;
		create table MV_MISSING_VALUE AS
		select *
		from pankaj.mv_yield_detail_mm
		where "&amp;amp;mindate."dt &amp;lt;= PROCESSED_DTTM &amp;lt;="&amp;amp;maxdate."dt;
	quit;
	
	/*2. Generate the table with proc sql with varname and type*/
	
	proc sql ;
		create table varlist_1 as
		select name, type from  dictionary.columns
		where libname = upcase("work") and memname = upcase("MV_MISSING_VALUE");
	quit;

	/*3. Looping through the Variables and checking the Data Type */
 	%do I=1 %to %sysfunc(countw(&amp;amp;varlist)); 
	 		%let var = %scan(&amp;amp;varlist, &amp;amp;I);
			%put &amp;amp;var.;

			/*3.1To check the Data Type for all the varibales in varlist. */		
			proc sql noprint;
				select type into: t separated by ' ' from varlist_1
				where name="&amp;amp;var.";
			quit;
			%put check=&amp;amp;t.;


	/*4. Formatting with Character Values*/
	%if &amp;amp;t=char %then %do;
		/*length var $32;*/
		proc freq data=work.MV_MISSING_VALUE;
			format &amp;amp;var. $missfmt.; /* apply format for the duration of this PROC */
			tables &amp;amp;var. / missing missprint nocum  out= Final_Output_&amp;amp;var ;
		run;

		/*DATA Step for Filtering Only Missing Values in a separate Tables*/
		DATA Final_Output_&amp;amp;var;
			set Final_Output_&amp;amp;var;
			where put (&amp;amp;var., $missfmt.) in ("Missing");
		run;		
	%end; 

	/*5. Formatting with Numeric Format*/
	%else %do;
		proc freq data=work.MV_MISSING_VALUE;
			format &amp;amp;var. missfmt.; /* apply format for the duration of this PROC */
			tables &amp;amp;var. / missing  missprint nocum out= Final_Output_&amp;amp;var ;
		run;
	
		/*DATA Step for Filtering Only Missing Values in a separate Tables*/
		DATA Final_Output_&amp;amp;var;
			set Final_Output_&amp;amp;var;
			where put (&amp;amp;var., missfmt.) in ("Missing");
		run;
		
	%end;

	
	/*6. Add new variable*/
	data Final_Output_&amp;amp;var ; 
			set Final_Output_&amp;amp;var ;
			VARNAME = "&amp;amp;var" ;
			
		run ;


	%end;
%mend;
%abc;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is what I am intended to do in One Macro. I have attached the sample data.&lt;/P&gt;&lt;P&gt;At last, I want the Missing % along with the Variable name.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 16:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/446241#M28867</guid>
      <dc:creator>narulap</dc:creator>
      <dc:date>2018-03-16T16:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: Adding New Missing Observation in Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/446385#M28875</link>
      <description>&lt;P&gt;Please post example data in a&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;data step with datalines.&lt;/EM&gt;&lt;/STRONG&gt;&lt;U&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;Spreadsheets are mostly useless. They do not convey column attributes, and many of us don't open them for security reasons. Many organisations block their download.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 23:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/446385#M28875</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-16T23:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Adding New Missing Observation in Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/446399#M28877</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/179907"&gt;@narulap&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Because many people here in this forum don't want to download Excel files (security concerns) a really quick and easy&amp;nbsp;way for you to create sample data from an Excel file is to use EG with the import wizard, select to include the data and then slightly modify the resulting generated data step. I've done this now for you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA sample;
    INFILE DATALINES4
        DLM='|'
        truncover
        DSD ;
    FORMAT
        SHIFT_CURING_DATE DATE9.
        SHIFT_BUILD_DATE DATE9.
        PROCESSED_DTTM   DATETIME22.3 ;

    INPUT
        BATCH_ID         : $7.
        TREAD            : $5.
        TIRESIZE         : $3.
        CUSTOMER         : $3.
        CUSTOMER_INTENDED : $5.
        ARTICLE7         : $6.
        TIRE_TYPE        : $2.
        WAREHOUSED       : BEST32.
        TBM_STAGE1       : $5.
        TBM_STAGE2       : $1.
        CURING_STAGE1    : $5.
        BLADDER          : $6.
        MOLD             : $7.
        SHIFT_CURING_DATE : BEST32.
        SHIFT_BUILD_DATE : BEST32.
        PROCESSED_DTTM   : BEST32. ;
DATALINES4;
1234567|7480Z| |abc|Trade|123456|RE|.|TBA21| |CUFA0|CUAGDF|M410946|21211|21211|1832722557
1234568|38128|225|abc|Trade|123457|RE|.|TB201| |CUE18|CUAGDF|M415224|21196|21196|1831425644
1234569|37371|226|abc|Trade|123458|RE|.|TB214| |CUG07|CUAGDF|M412290|21187|21187|1830649694
1234570|7047|227|abc|Ford|123459|OE|.|TB302| |CUC19|CUAGDF|M411967|21200|21200|1831768923
1234571|YWL| |abc|Trade|123460|RE|.|TB309| |CUJ03|CUAGDF|M413836|21200|21198|1831735814
1234572|38072|264|abc|Trade|123461|RE|.|TB217| |CUG15|CUAGDF|M417268|21189|21184|1830831636
1234573|7372Z|265| |Trade|123462|RE|.|TBA21| |CUCB0|CUAGDF|M412572|21186|21186|1830540294
1234574|OPB|266|abc|Trade|123463|RE|1|TB217| |CUI42|CUAGDF|M404461|21191|21191|1830969455
1234575|YLO|267|abc|Trade|123464|RE|1|TB215| |CUG01|CUAGDF|M412529|21211|21211|1832723202
1234576|37428|268|abc|Trade|123465|RE|1|TB213| |CUA03|CUAGDF|M408985|21194|21193|1831220366
1234577|38072|269|abc|Trade|123466|RE|1|TB217| |CUI37|CUAGDF|M417266|21198|21198|1831603331
;;;;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro you've posted is not fully working with the data you've posted - so that's may be something else you want to test next time before posting code together with data (unless your problem is to make the code work without errors).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not fully clear what you're actually trying to achieve: Just create reports or collect some stats about missings in a SAS table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Always try to keep things simple and make it work with simple code before you start wrapping macro code around. And also search the forums here first as often someone else had already a similar question and there is a solution around.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following solution might give you some ideas what you could be doing:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/General-SAS-Programming/How-to-count-non-missing-rows-for-all-columns-and-store-results/m-p/403982/highlight/true#M50771" target="_blank"&gt;https://communities.sas.com/t5/General-SAS-Programming/How-to-count-non-missing-rows-for-all-columns-and-store-results/m-p/403982/highlight/true#M50771&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Mar 2018 01:06:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/446399#M28877</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-03-17T01:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: Adding New Missing Observation in Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/446430#M28883</link>
      <description>&lt;P&gt;Okay, I am new to this community. It will not be uploaded next time. Thanks for sharing the info.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Mar 2018 12:17:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/446430#M28883</guid>
      <dc:creator>narulap</dc:creator>
      <dc:date>2018-03-17T12:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: Adding New Missing Observation in Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/446829#M28897</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;for being so kind. I am new to this community and for sure will not attach the files next time &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 15:20:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/446829#M28897</guid>
      <dc:creator>narulap</dc:creator>
      <dc:date>2018-03-19T15:20:10Z</dc:date>
    </item>
    <item>
      <title>Re: Adding New Missing Observation in Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/448594#M29022</link>
      <description>&lt;P&gt;Thank you all for your valuable inputs. I have changed the code and everything is running in a single macro which was my assignment.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2018 11:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Adding-New-Missing-Observation-in-Data-Step/m-p/448594#M29022</guid>
      <dc:creator>narulap</dc:creator>
      <dc:date>2018-03-26T11:12:48Z</dc:date>
    </item>
  </channel>
</rss>

