<?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: convert to missing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/convert-to-missing/m-p/696444#M212730</link>
    <description>&lt;P&gt;As always, the useless wide format makes the code unnecessarily complicated.&lt;/P&gt;
&lt;P&gt;Let's beat this monstrosity into shape:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data ttt;
input IDNumber CriticalPoint t1901 t1902 t1903 t1904 t1905 t1906 t1907 t1908 t1909 t1910;
cards;
1 1903 2 3 4 6 8 7 2 3 5 8
2 1902 5 3 1 2 3 4 5 7 6 9
3 1905 2 4 6 8 9 7 5 6 8 3
;

proc transpose
  data=ttt
  out=long
;
by idnumber;
var t:;
run;

data long;
set long;
period = input('20'!!substr(_name_,2),yymmn6.);
format period yymmd7.;
drop _name_;
run;

data have;
set ttt;
cp = input('20'!!put(criticalpoint,z4.),yymmn6.);
format cp yymmd7.;
run;

data long;
set long;
period = input('20'!!substr(_name_,2),yymmn6.);
format period yymmd7.;
drop _name_;
run;

data have;
set ttt;
cp = input('20'!!put(criticalpoint,z4.),yymmn6.);
format cp yymmd7.;
keep idnumber cp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then, all that's needed is this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge
  have
  long
;
by idnumber;
if -1 le intck('month',cp,period) le 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 04 Nov 2020 11:22:24 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-11-04T11:22:24Z</dc:date>
    <item>
      <title>convert to missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-to-missing/m-p/696418#M212711</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;For each person ID there are values in 10 months (From Jana 2019 till OCT 2019).&lt;/P&gt;
&lt;P&gt;The structure of the name is tYYMM.&lt;/P&gt;
&lt;P&gt;For each person ID there is also information of&amp;nbsp;CriticalPoint (This is the date in structure YYMM).&lt;/P&gt;
&lt;P&gt;For each ID I want to convert values to missing by the following rule:&lt;/P&gt;
&lt;P&gt;for each ID there will be follow up of 3 months from 1 month after&amp;nbsp;CriticalPoint.&lt;/P&gt;
&lt;P&gt;for example:&lt;/P&gt;
&lt;P&gt;ID=1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CriticalPoint=1903&lt;/P&gt;
&lt;P&gt;so values in t1904 t1905 t1906 should be non missing and other values should be missing&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID=3&lt;/P&gt;
&lt;P&gt;CriticalPoint=1905&lt;/P&gt;
&lt;P&gt;so values in t1906 t1907 t1908 should be non missing and other values should be missing&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In real life there is a data set with many rows so should find a clever way to do it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data ttt;
input IDNumber CriticalPoint t1901 t1902 t1903 t1904 t1905 t1906 t1907 t1908 t1909 t1910 ;
cards;
1 1903 2 3 4 6 8 7 2 3 5 8
2 1902 5 3 1 2 3 4 5 7 6 9
3 1905 2 4 6 8 9 7 5 6 8 3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Nov 2020 09:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-to-missing/m-p/696418#M212711</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-11-04T09:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: convert to missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-to-missing/m-p/696420#M212712</link>
      <description>&lt;P&gt;How about&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data ttt;
input IDNumber CriticalPoint t1901 t1902 t1903 t1904 t1905 t1906 t1907 t1908 t1909 t1910 ;
cards;
1 1903 2 3 4 6 8 7 2 3 5 8
2 1902 5 3 1 2 3 4 5 7 6 9
3 1905 2 4 6 8 9 7 5 6 8 3
;
run;

data want(drop=i j);
   set ttt;
   array t{*} t1901-t1910;

   do i = 1 to dim(t);
      if CriticalPoint = input(compress(vname(t[i]),, 'kd'), 8.) then leave;
   end;

   do j = 1 to dim(t);
      if not (i+1 &amp;lt;= j &amp;lt;= i+3) then t[j] = .;
   end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;IDNumber CriticalPoint t1901 ------- t1910 
1        1903          . . . 6 8 7 . . . .  
2        1902          . . 1 2 3 . . . . .  
3        1905          . . . . . 7 5 6 . .  &lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Nov 2020 09:29:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-to-missing/m-p/696420#M212712</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-04T09:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: convert to missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-to-missing/m-p/696422#M212713</link>
      <description>&lt;P&gt;Dealing with one year starting in JAN makes life easy, as month can be used as a pointer to an array:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data ttt;
input IDNumber CriticalPoint t1901 t1902 t1903 t1904 t1905 t1906 t1907 t1908 t1909 t1910 ;
cards;
1 1903 2 3 4 6 8 7 2 3 5 8
2 1902 5 3 1 2 3 4 5 7 6 9
3 1905 2 4 6 8 9 7 5 6 8 3
;
run;
data want;
 set ttt;
      array tx {10} t1901-t1910;
      mm = CriticalPoint - 1900;
      do i = 1 to 10;
           if i &amp;lt; mm or I &amp;gt; mm+2 then call missing(tx(i));
     end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Nov 2020 09:43:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-to-missing/m-p/696422#M212713</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-11-04T09:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: convert to missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-to-missing/m-p/696423#M212714</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data wanted;
set ttt;
if CriticalPoint=1902 then do;
t1906=.;t1907=.;t1908=.;t1909=.;t1910=.;
t1901=.;t1902=.;
end;
if CriticalPoint=1903 then do;
t1907=.;t1908=.;t1909=.;t1910=.;
t1901=.;t1902=.;t1903=.;
end;
if CriticalPoint=1905 then do;
t1909=.;t1910=.;
t1901=.;t1902=.;t1903=.;t1904=.;t1905=.;
end;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I&amp;nbsp; would like to see a more useful way to do it&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 09:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-to-missing/m-p/696423#M212714</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-11-04T09:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: convert to missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-to-missing/m-p/696428#M212717</link>
      <description>&lt;P&gt;What do you mean? Both approaches above are useful?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 10:04:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-to-missing/m-p/696428#M212717</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-04T10:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: convert to missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-to-missing/m-p/696437#M212724</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
	input IDNumber CriticalPoint t1901 t1902 t1903 t1904 t1905 t1906 t1907 t1908 
		t1909 t1910;
	cards;
1 1903 2 3 4 6 8 7 2 3 5 8
2 1902 5 3 1 2 3 4 5 7 6 9
3 1905 2 4 6 8 9 7 5 6 8 3
;
run;

data want;
	set have;
	array t[10] t1901-t1910;
	array tmp[3] _temporary_;

	do i=1 to dim(t);

		do j=1 to 3;
			k=criticalpoint+j;
			tmp[j]=vvaluex(cats("t", k));

			if vname(t[i])=cats("t", k) then
				do;
					t[i]=tmp[j];
					goto missing;
				end;
		end;
missing:

		if vname(t[i]) ne cats("t", k) then
			do;
				t[i]=.;
			end;
	end;
	drop i--k;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Nov 2020 10:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-to-missing/m-p/696437#M212724</guid>
      <dc:creator>hhinohar</dc:creator>
      <dc:date>2020-11-04T10:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: convert to missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-to-missing/m-p/696442#M212728</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;For each person ID there are values in 10 months (From Jana 2019 till OCT 2019).&lt;/P&gt;
&lt;P&gt;The structure of the name is tYYMM.&lt;/P&gt;
&lt;P&gt;For each person ID there is also information of&amp;nbsp;CriticalPoint (This is the date in structure YYMM).&lt;/P&gt;
&lt;P&gt;For each ID I want to convert values to missing by the following rule:&lt;/P&gt;
&lt;P&gt;for each ID there will be follow up of 3 months from 1 month after&amp;nbsp;CriticalPoint.&lt;/P&gt;
&lt;P&gt;for example:&lt;/P&gt;
&lt;P&gt;ID=1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CriticalPoint=1903&lt;/P&gt;
&lt;P&gt;so values in t1904 t1905 t1906 should be non missing and other values should be missing&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID=3&lt;/P&gt;
&lt;P&gt;CriticalPoint=1905&lt;/P&gt;
&lt;P&gt;so values in t1906 t1907 t1908 should be non missing and other values should be missing&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In real life there is a data set with many rows so should find a clever way to do it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data ttt;
input IDNumber CriticalPoint t1901 t1902 t1903 t1904 t1905 t1906 t1907 t1908 t1909 t1910 ;
cards;
1 1903 2 3 4 6 8 7 2 3 5 8
2 1902 5 3 1 2 3 4 5 7 6 9
3 1905 2 4 6 8 9 7 5 6 8 3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Again, if you have a LONG data set rather than a wide data set, this is simple to do. You really don't seem to have grasped this point as we have discussed this many times before.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    if month&amp;lt;intnx('month',criticalpoint,1,'b') or month&amp;gt;intnx('month',criticalpoint,
        4,'b') then call missing(t);
run;
    &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This assumes you have a true SAS date value for CRITICALPOINT, a new variable named MONTH which is also a true SAS date value, and your t-variables are named T. And of course, the analysis after you do this is also simplified with a long data set compared to a wide data set, as we have been discussing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In addition, if your t-variables cross a year boundary, so they contain t1910 t1911 t1912 t2001 t2002 &lt;EM&gt;etc&lt;/EM&gt;., none of the other solutions work without additional modification, but the long data set solution with actual SAS dates works properly without any additional modification.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 11:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-to-missing/m-p/696442#M212728</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-04T11:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: convert to missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-to-missing/m-p/696444#M212730</link>
      <description>&lt;P&gt;As always, the useless wide format makes the code unnecessarily complicated.&lt;/P&gt;
&lt;P&gt;Let's beat this monstrosity into shape:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data ttt;
input IDNumber CriticalPoint t1901 t1902 t1903 t1904 t1905 t1906 t1907 t1908 t1909 t1910;
cards;
1 1903 2 3 4 6 8 7 2 3 5 8
2 1902 5 3 1 2 3 4 5 7 6 9
3 1905 2 4 6 8 9 7 5 6 8 3
;

proc transpose
  data=ttt
  out=long
;
by idnumber;
var t:;
run;

data long;
set long;
period = input('20'!!substr(_name_,2),yymmn6.);
format period yymmd7.;
drop _name_;
run;

data have;
set ttt;
cp = input('20'!!put(criticalpoint,z4.),yymmn6.);
format cp yymmd7.;
run;

data long;
set long;
period = input('20'!!substr(_name_,2),yymmn6.);
format period yymmd7.;
drop _name_;
run;

data have;
set ttt;
cp = input('20'!!put(criticalpoint,z4.),yymmn6.);
format cp yymmd7.;
keep idnumber cp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then, all that's needed is this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge
  have
  long
;
by idnumber;
if -1 le intck('month',cp,period) le 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Nov 2020 11:22:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-to-missing/m-p/696444#M212730</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-04T11:22:24Z</dc:date>
    </item>
  </channel>
</rss>

