<?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: how do I input 4 different variables in the same datalines and only keep those lines that matche in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-input-4-different-variables-in-the-same-datalines-and/m-p/341722#M78249</link>
    <description>&lt;P&gt;i prepared 2 different datasets have and have2. i tried they are correct. if you want you can change data formats.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/* &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; part one &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; */&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;INPUT comment $ 30.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;M10/21/46CADYA&lt;BR /&gt;F11/11/50CLINEB&lt;BR /&gt;M11/11/52SMITHA&lt;BR /&gt;F10/10/80OPPENHEIMERB&lt;BR /&gt;M04/04/60JOSEA&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.QUERY_FOR_HAVE AS&lt;BR /&gt;SELECT /* gender */&lt;BR /&gt;(SUBSTR(t1.comment, 1, 1)) AS gender,&lt;BR /&gt;/* birthday */&lt;BR /&gt;(SUBSTR(t1.comment,2,8)) AS birthday,&lt;BR /&gt;/* status */&lt;BR /&gt;(substr(t1.comment,(LENGTH(t1.comment)),1)) AS status,&lt;BR /&gt;/* name */&lt;BR /&gt;(substr(t1.comment,10, LENGTH(t1.comment)-10)) AS name&lt;BR /&gt;FROM WORK.HAVE t1;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;part two &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; */&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have2;&lt;BR /&gt;INPUT comment2 $ 30.;&lt;BR /&gt;DATALINES;&lt;/P&gt;&lt;P&gt;M10/21/46CODY155&lt;BR /&gt;F11/11/50CLEIN166&lt;BR /&gt;F11/11/52SMITH185&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.QUERY_FOR_HAVE_2 AS&lt;BR /&gt;SELECT /* gender */&lt;BR /&gt;(SUBSTR(t1.comment2, 1, 1)) AS gender,&lt;BR /&gt;/* birthday */&lt;BR /&gt;(SUBSTR(t1.comment2,2,8)) AS birthday,&lt;BR /&gt;/* status */&lt;BR /&gt;(substr(t1.comment2,(LENGTH(t1.comment2))-2,3)) AS status,&lt;BR /&gt;/* name */&lt;BR /&gt;(substr(t1.comment2,10, LENGTH(t1.comment2)-12)) AS name&lt;BR /&gt;FROM WORK.HAVE2 t1;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Mar 2017 18:52:57 GMT</pubDate>
    <dc:creator>Yavuz</dc:creator>
    <dc:date>2017-03-16T18:52:57Z</dc:date>
    <item>
      <title>how do I input 4 different variables in the same datalines and only keep those lines that matches?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-input-4-different-variables-in-the-same-datalines-and/m-p/341684#M78233</link>
      <description>&lt;P&gt;Hello everyone&lt;/P&gt;&lt;P&gt;How do I input the below dataline into sas with variable : gender, birthday, name, status(last letter of each line) for fisrt dataset&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;M10/21/46CADYA&lt;BR /&gt;F11/11/50CLINEB&lt;BR /&gt;M11/11/52SMITHA&lt;BR /&gt;F10/10/80OPPENHEIMERB&lt;BR /&gt;M04/04/60JOSEA&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;second dataset with variables gender birthday name height&lt;/P&gt;&lt;P&gt;datalines:&lt;/P&gt;&lt;P&gt;M10/21/46CODY155&lt;BR /&gt;F11/11/50CLEIN166&lt;BR /&gt;F11/11/52SMITH185&lt;BR /&gt;F10/10/80OPPENHAIMER199&lt;BR /&gt;M02/07/60JOSA173&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I also want to keep those rows that are same(matches) in two datalines with all variables(including status and height)&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 17:21:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-input-4-different-variables-in-the-same-datalines-and/m-p/341684#M78233</guid>
      <dc:creator>songforu-8sdsa</dc:creator>
      <dc:date>2017-03-16T17:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: how do I input 4 different variables in the same datalines and only keep those lines that matche</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-input-4-different-variables-in-the-same-datalines-and/m-p/341721#M78248</link>
      <description>&lt;P&gt;Hi, see code below. None of your data matches up the way you listed it because either names are different or gender is different, I don't know if those are typos in the names or if that's how your data is. But I changed the first name in the second dataset so you can see what the dataset 'want' looks like if all three values match.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input Gender $ 1 DOBin $ 2-9 NameStatus $ 10-25;
datalines;
M10/21/46CADYA
F11/11/50CLINEB
M11/11/52SMITHA
F10/10/80OPPENHEIMERB
M04/04/60JOSEA
;
run;

data have1;
set have1;
format DOB mmddyy8.;
DOB=input(DOBin,mmddyy8.);
Name=substr(NameStatus,1,length(NameStatus)-1);
Status=substr(NameStatus,length(NameStatus));
drop DOBin NameStatus;
run;

proc sort data=have1;
by gender DOB Name;
run;

data have2;
input Gender $ 1 DOBin $ 2-9 NameHeight $ 10-25;
datalines;
M10/21/46CADY155
F11/11/50CLEIN166
F11/11/52SMITH185
F10/10/80OPPENHAIMER199
M02/07/60JOSA173
;
run;

data have2;
set have2;
format DOB mmddyy8.;
DOB=input(DOBin,mmddyy8.);
Name=compress(NameHeight,'','d');
Height=input(compress(NameHeight,'','a'),3.);
drop DOBin NameHeight;
run;

proc sort data=have2;
by gender DOB Name;
run;

data want;
merge have1(in=a) have2(in=b);
by gender DOB Name;
if a and b;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Mar 2017 18:48:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-input-4-different-variables-in-the-same-datalines-and/m-p/341721#M78248</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-03-16T18:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: how do I input 4 different variables in the same datalines and only keep those lines that matche</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-input-4-different-variables-in-the-same-datalines-and/m-p/341722#M78249</link>
      <description>&lt;P&gt;i prepared 2 different datasets have and have2. i tried they are correct. if you want you can change data formats.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/* &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; part one &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; */&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;INPUT comment $ 30.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;M10/21/46CADYA&lt;BR /&gt;F11/11/50CLINEB&lt;BR /&gt;M11/11/52SMITHA&lt;BR /&gt;F10/10/80OPPENHEIMERB&lt;BR /&gt;M04/04/60JOSEA&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.QUERY_FOR_HAVE AS&lt;BR /&gt;SELECT /* gender */&lt;BR /&gt;(SUBSTR(t1.comment, 1, 1)) AS gender,&lt;BR /&gt;/* birthday */&lt;BR /&gt;(SUBSTR(t1.comment,2,8)) AS birthday,&lt;BR /&gt;/* status */&lt;BR /&gt;(substr(t1.comment,(LENGTH(t1.comment)),1)) AS status,&lt;BR /&gt;/* name */&lt;BR /&gt;(substr(t1.comment,10, LENGTH(t1.comment)-10)) AS name&lt;BR /&gt;FROM WORK.HAVE t1;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;part two &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; */&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have2;&lt;BR /&gt;INPUT comment2 $ 30.;&lt;BR /&gt;DATALINES;&lt;/P&gt;&lt;P&gt;M10/21/46CODY155&lt;BR /&gt;F11/11/50CLEIN166&lt;BR /&gt;F11/11/52SMITH185&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.QUERY_FOR_HAVE_2 AS&lt;BR /&gt;SELECT /* gender */&lt;BR /&gt;(SUBSTR(t1.comment2, 1, 1)) AS gender,&lt;BR /&gt;/* birthday */&lt;BR /&gt;(SUBSTR(t1.comment2,2,8)) AS birthday,&lt;BR /&gt;/* status */&lt;BR /&gt;(substr(t1.comment2,(LENGTH(t1.comment2))-2,3)) AS status,&lt;BR /&gt;/* name */&lt;BR /&gt;(substr(t1.comment2,10, LENGTH(t1.comment2)-12)) AS name&lt;BR /&gt;FROM WORK.HAVE2 t1;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 18:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-input-4-different-variables-in-the-same-datalines-and/m-p/341722#M78249</guid>
      <dc:creator>Yavuz</dc:creator>
      <dc:date>2017-03-16T18:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: how do I input 4 different variables in the same datalines and only keep those lines that matche</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-input-4-different-variables-in-the-same-datalines-and/m-p/341724#M78250</link>
      <description>&lt;P&gt;This kinda of question always brought me back to the good old days when programming does matter :), You will need to read SAS docs on input, infile, informats etc.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename FT15F001 temp lrecl=512; 

data test;
infile FT15F001  length=len ;
input @;
len=len-10;
input gender $1.
       birthday mmddyy8. 
        name $varying100. len status $1.;

format birthday mmddyy8.;
parmcards4;;;;
M10/21/46CADYA
F11/11/50CLINEB
M11/11/52SMITHA
F10/10/80OPPENHEIMERB
M04/04/60JOSEA
;;;;
run;

filename FT15F001 clear;


filename FT15F001 temp lrecl=512; 

data test2;
infile FT15F001  length=len ;
input @;
len=len-12;
input gender $1.
       birthday mmddyy8. 
        name $varying100. len height;

format birthday mmddyy8.;
parmcards4;;;;
M10/21/46CODY155
F11/11/50CLEIN166
F11/11/52SMITH185
F10/10/80OPPENHAIMER199
M02/07/60JOSA173
;;;;
run;

filename FT15F001 clear;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Mar 2017 19:07:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-input-4-different-variables-in-the-same-datalines-and/m-p/341724#M78250</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2017-03-16T19:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: how do I input 4 different variables in the same datalines and only keep those lines that matche</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-input-4-different-variables-in-the-same-datalines-and/m-p/341791#M78287</link>
      <description>&lt;P&gt;I added one dataline to show a matching case:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
length gender $1 name $20 birthday 8 status $1 line $100;
format birthday yymmdd10.;
if not prxId then prxId + prxParse("@([MF])(\d{1,2}/\d{1,2}/\d{1,2})(\D+)(\w)@");
input line;
if prxMatch(prxId, line) then do;
    gender = prxPosn(prxId, 1, line);
    birthday = input(prxPosn(prxId, 2, line), mmddyy8.);
    name = prxPosn(prxId, 3, line);
    status = prxPosn(prxId, 4, line);
    output;
    end;
drop line prxId;
datalines;
M10/21/46CADYA
F11/11/50CLINEB
M11/11/52SMITHA
F10/10/80OPPENHEIMERB
M04/04/60JOSEA
F11/11/52SMITHA
;

data b;
length gender $1 name $20 birthday 8 weight 8 line $100;
format birthday yymmdd10.;
if not prxId then prxId + prxParse("@([MF])(\d{1,2}/\d{1,2}/\d{1,2})(\D+)(\d+)@");
input line;
if prxMatch(prxId, line) then do;
    gender = prxPosn(prxId, 1, line);
    birthday = input(prxPosn(prxId, 2, line), mmddyy8.);
    name = prxPosn(prxId, 3, line);
    weight = input(prxPosn(prxId, 4, line), best.);
    output;
    end;
drop line prxId;
datalines;
M10/21/46CODY155
F11/11/50CLEIN166
F11/11/52SMITH185
F10/10/80OPPENHAIMER199
M02/07/60JOSA173
;

proc sql;
create table ab as
select a.*, b.weight
from a natural join b;
select * from ab;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Mar 2017 22:12:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-input-4-different-variables-in-the-same-datalines-and/m-p/341791#M78287</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-03-16T22:12:11Z</dc:date>
    </item>
  </channel>
</rss>

