<?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: Follow up information by number of months since joined research in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Follow-up-information-by-number-of-months-since-joined-research/m-p/646365#M193330</link>
    <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="photo.PNG" style="width: 608px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39241i304E4731479F0F92/image-size/large?v=v2&amp;amp;px=999" role="button" title="photo.PNG" alt="photo.PNG" /&gt;&lt;/span&gt;Thank you very much.&lt;/P&gt;
&lt;P&gt;The only problem is that in the wanted data set there should be columns: g1,g2,g3,g4,g5 instead of&amp;nbsp;&lt;/P&gt;
&lt;P&gt;g2001 ,g2002,g2003,g2004,g2005&lt;/P&gt;
&lt;P&gt;The logic is that the important information is when was the grade with relation to how many months since joining&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 09 May 2020 11:06:53 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2020-05-09T11:06:53Z</dc:date>
    <item>
      <title>Follow up information by number of months since joined research</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up-information-by-number-of-months-since-joined-research/m-p/646357#M193326</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;There are 5 data sets:&lt;/P&gt;
&lt;P&gt;data set tbl1 with information for each customer(ID) when he joined the research.&lt;/P&gt;
&lt;P&gt;The join date is written as year+month (YYMM) .&lt;/P&gt;
&lt;P&gt;for example: 2001 is JAN 2020,2002 is FEB 2020, 2003 is MARCH 2020 and so on.&lt;/P&gt;
&lt;P&gt;Data set T2001 includes information of grade for each ID in JAN 2020&lt;/P&gt;
&lt;P&gt;Data set T2002 includes information of grade for each ID in FEB 2020&lt;/P&gt;
&lt;P&gt;Data set T2003 includes information of grade for each ID in MAR 2020&lt;/P&gt;
&lt;P&gt;Data set T2004 includes information of grade for each ID in APR 2020&lt;/P&gt;
&lt;P&gt;Data set T2005 includes information of grade for each ID in MAY 2020&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since we are in month MAY today the last information is of MAY 2020.&lt;/P&gt;
&lt;P&gt;I want to create a data set that will contain for each customer information if grades since he joined the research until now (MAY 2020).&lt;/P&gt;
&lt;P&gt;g1 is grade 1month after joining the research&lt;/P&gt;
&lt;P&gt;g2 is grade 2 months after joining the research&lt;/P&gt;
&lt;P&gt;g3 is grade 3 months after joining the research&lt;/P&gt;
&lt;P&gt;and so on&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data tbl1;
input ID  JoinYYMM;
cards;
1 2001
2 2003
3 2003
4 2002
;
Run;

Data T2001;
input ID grade;
cards;
1 10
2 9
3 9
4 8
;
run;

Data T2002;
input ID grade;
cards;
1 12
2 9
3 7
4 8
;
run;

Data T2003;
input ID grade;
cards;
1 7
2 9
3 6
4 8
;
run;

Data T2004;
input ID grade;
cards;
1 5
2 8
3 6
4 9
;
run;

Data T2005;
input ID grade;
cards;
1 8
2 11
3 7
4 10
;
run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Data wanted;&lt;BR /&gt;input ID FollowUpPeriod g1 g2 g3 g4 g5;&lt;BR /&gt;cards;&lt;BR /&gt;1 2001-2005 10 12 7 5 8&lt;BR /&gt;2 2003-2005 9 8 11 . .&lt;BR /&gt;3 2003-2005 6 6 7 . .&lt;BR /&gt;4 2002-2005 8 8 9 10 .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 May 2020 08:51:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up-information-by-number-of-months-since-joined-research/m-p/646357#M193326</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-05-09T08:51:48Z</dc:date>
    </item>
    <item>
      <title>Re: Follow up information by number of months since joined research</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up-information-by-number-of-months-since-joined-research/m-p/646359#M193327</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an attempt to achieve this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	retain id FollowUpPeriod g:;
	
	merge tbl1 T2001 (rename= (grade=g2001)) 
			   T2002 (rename= (grade=g2002)) 
			   T2003 (rename= (grade=g2003)) 
			   T2004 (rename= (grade=g2004)) 
			   T2005 (rename= (grade=g2005));
	by ID;
	FollowUpPeriod = catx("-",joinYYMM,2005);
	
	array _a (*) g:;

	do i=1 to dim(_a);
		if substr(vname(_a(i)),2) &amp;lt; joinYYMM then do;
			call missing (_a(i));
		end;
	end;
	drop i joinYYMM;
run;

proc transpose data=have out=have_tr;
	var g:;
	by id FollowUpPeriod;
run;

proc transpose data=have_tr (where=(col1 ne .)) out=want (drop=_:) prefix=g;
	var col1;
	by id FollowUpPeriod;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture d’écran 2020-05-09 à 11.26.58.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39238iF725B09E1F4BD39B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture d’écran 2020-05-09 à 11.26.58.png" alt="Capture d’écran 2020-05-09 à 11.26.58.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Sat, 09 May 2020 09:27:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up-information-by-number-of-months-since-joined-research/m-p/646359#M193327</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-09T09:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: Follow up information by number of months since joined research</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up-information-by-number-of-months-since-joined-research/m-p/646362#M193328</link>
      <description>&lt;P&gt;I highly recommend NOT using YYMM date format for your presentations, especially in year 2020 when 2001-2012 are easily construed as years instead of 2020 month 01-12.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might also consider a grid report showing the grades (since joining).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The individual data sets can be easily stacked using a name range list syntax&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;SET T2001-T2005;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After the data is stacked, a merge by ID can combine join dates with the stack and filtered the grade values according to your rules&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The YYMM date constructs can be read (i.e. parsed) into SAS date values using informat YYMMN4.&amp;nbsp; The N in the informat name means there is No separator between year and month.&amp;nbsp; I would recommend your date presentation be NLDATEYMM. (Jan 2020, Feb 2020, etc)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example - Data for code&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;Data joindates;
input ID  Join yymmN4.; format join NLDATEYMM.;
cards;
1 2001
2 2003
3 2003
4 2002
;

Data T2001;
input ID grade;
cards;
1 10
2 9
3 9
4 8
;

Data T2002;
input ID grade;
cards;
1 12
2 9
3 7
4 8
;

Data T2003;
input ID grade;
cards;
1 7
2 9
3 6
4 8
;

Data T2004;
input ID grade;
cards;
1 5
2 8
3 6
4 9
;

Data T2005;
input ID grade;
cards;
1 8
2 11
3 7
4 10
;
&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;Example - Combine and Report&lt;/P&gt;
&lt;PRE&gt;data stack(index=(id));
  set T2001-T2005 indsname=table;
  source = table;
  date = input(scan(table, -1, 'T'),yymmN4.);
  format date NLDATEYMM.;
  drop source;
run;

data combined;
  merge joindates stack;
  by id;

  grade_filtered = ifn(date &amp;lt; join, ., grade);&lt;BR /&gt;  months_since_join = 1 + intck('month', join, date);  * value for transpose ID;
run;

ods html file='report.html' style=plateau;

proc report data=combined;
  column id join grade_filtered,date;
  define id / group;
  define join / group;
  define date / '' across order=data;
  define grade_filtered / 'Grades' ;
run;

ods html close;&lt;/PRE&gt;
&lt;P&gt;Output&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RichardADeVenezia_0-1589019416527.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39240iB9A050FCB42EDE3C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RichardADeVenezia_0-1589019416527.png" alt="RichardADeVenezia_0-1589019416527.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If you want to create the pivoted data set (for reporting purposes?) a SQL and TRANSPOSE step is added.&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table stage1 as
  select * from 
  ( select id, join, grade, months_since_join
    , catx('-',put(join,NLDATEYMM.),put(max(date),NLDATEYMM.)) as FollowUpPeriod length=17
    from combined
    group by id, join
  ) union
  ( select distinct 0, 0, 0, months_since_join from combined )
  order by id, months_since_join
  ;

proc transpose data=stage1 prefix=g out=want(where=(id&amp;gt;0) drop=_name_);
  by id join FollowUpPeriod;
  id months_since_join;
  var grade;
  where months_since_join &amp;gt; 0;
run;
&lt;/PRE&gt;
&lt;P&gt;Result data set&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="transposed.png" style="width: 443px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39242i75F2F6B5DA24774D/image-size/large?v=v2&amp;amp;px=999" role="button" title="transposed.png" alt="transposed.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 May 2020 12:30:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up-information-by-number-of-months-since-joined-research/m-p/646362#M193328</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-05-09T12:30:16Z</dc:date>
    </item>
    <item>
      <title>Re: Follow up information by number of months since joined research</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up-information-by-number-of-months-since-joined-research/m-p/646365#M193330</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="photo.PNG" style="width: 608px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39241i304E4731479F0F92/image-size/large?v=v2&amp;amp;px=999" role="button" title="photo.PNG" alt="photo.PNG" /&gt;&lt;/span&gt;Thank you very much.&lt;/P&gt;
&lt;P&gt;The only problem is that in the wanted data set there should be columns: g1,g2,g3,g4,g5 instead of&amp;nbsp;&lt;/P&gt;
&lt;P&gt;g2001 ,g2002,g2003,g2004,g2005&lt;/P&gt;
&lt;P&gt;The logic is that the important information is when was the grade with relation to how many months since joining&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 May 2020 11:06:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up-information-by-number-of-months-since-joined-research/m-p/646365#M193330</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-05-09T11:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: Follow up information by number of months since joined research</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up-information-by-number-of-months-since-joined-research/m-p/646368#M193332</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you tried the code provided above? It will give you the expected output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Sat, 09 May 2020 11:18:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up-information-by-number-of-months-since-joined-research/m-p/646368#M193332</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-09T11:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Follow up information by number of months since joined research</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up-information-by-number-of-months-since-joined-research/m-p/646420#M193359</link>
      <description>&lt;P&gt;Thank you so much.&lt;/P&gt;
&lt;P&gt;It is a very clever way.&lt;/P&gt;
&lt;P&gt;I want to ask please a few questions:&lt;/P&gt;
&lt;PRE&gt;date = input(scan(table, -1, 'T'),yymmN4.);&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;I see that the target is to get for each observation the data set source name.(for example T2002)&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;Then you want to take sub-string that contain only date figures (For example: 2002).&lt;/P&gt;
&lt;P&gt;Can you explain please what is the meaning of '-1' in SCAN function?&lt;/P&gt;
&lt;P&gt;Can you also use SUBST(table,2,4) ?&lt;/P&gt;
&lt;P&gt;Then I see that you use INPUT function with YYMMN4. format in order to convert it to SAS date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May you also explain please what is the format&amp;nbsp;NLDATEYMM?&lt;/P&gt;
&lt;P&gt;As I understand it is only change the display of the date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 May 2020 20:35:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up-information-by-number-of-months-since-joined-research/m-p/646420#M193359</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-05-09T20:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: Follow up information by number of months since joined research</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up-information-by-number-of-months-since-joined-research/m-p/646427#M193363</link>
      <description>&lt;P&gt;The SCAN function allows you to extract&amp;nbsp;&lt;EM&gt;words&lt;/EM&gt; from string, and to specify what characters are the word&amp;nbsp;&lt;EM&gt;delimiters&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The INDSNAME= option names a temporary variable that will contain the active data set being read from the tables identified by the SET T2001-T2005 statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The values will be&amp;nbsp;&lt;FONT size="3"&gt;&lt;FONT face="courier new,courier"&gt;WORK.T2001,&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;WORK.T2002,&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;WORK.T2003,&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;WORK.T2004,&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;WORK.T2005&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;I told SCAN to take the -1st word from those values using the letter T as the word delimiter.&amp;nbsp; -1 means get the word counted from the right hand side instead of the right hand side.&amp;nbsp; The +1st word with delimiter T is "WORK.".&amp;nbsp; At this point the scanned word should be digits representing date part YYMM, according to the naming construct conventions you are working with or imposing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The same YYMM portion could have been extracted with SUBSTR(SCAN(table,2,'.'),2)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The YYMM string is input as a SAS date value using &lt;STRONG&gt;informat&lt;/STRONG&gt; YYMMN4.&lt;/P&gt;
&lt;P&gt;Because using the same YYMM date representation in viewers and output would be confusing I recommended using &lt;STRONG&gt;format &lt;/STRONG&gt;NLDATEYMM.&lt;/P&gt;
&lt;P&gt;The NLDATEYMM. format renders a SAS date value as a string with the construct MON YYYY, where MON is the three character month abbreviation and the YYYY is the 4 digits of the year.&lt;/P&gt;</description>
      <pubDate>Sat, 09 May 2020 22:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up-information-by-number-of-months-since-joined-research/m-p/646427#M193363</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-05-09T22:35:03Z</dc:date>
    </item>
  </channel>
</rss>

