<?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: Need to find if record is exist or not in input file through mainframe sas in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892770#M39713</link>
    <description>&lt;P&gt;Should the message be in a dataset or a flat file?&lt;/P&gt;</description>
    <pubDate>Tue, 05 Sep 2023 17:00:40 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-09-05T17:00:40Z</dc:date>
    <item>
      <title>Need to find if record is exist or not in input file through mainframe sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892472#M39687</link>
      <description>In input file there are records as below&lt;BR /&gt;Abc&lt;BR /&gt;Xyz&lt;BR /&gt;Tdg&lt;BR /&gt;Efg&lt;BR /&gt;&lt;BR /&gt;I want to check if xyz is there or not&lt;BR /&gt;&lt;BR /&gt;Data out_nme;&lt;BR /&gt;Infile inpt;&lt;BR /&gt;Input @3 var1 char$3.;&lt;BR /&gt;If var1 ='xyz' then do;&lt;BR /&gt;Put 'record found';&lt;BR /&gt;End;&lt;BR /&gt;Count1=index(var1,'xyz);&lt;BR /&gt;File out_name;&lt;BR /&gt;Put count1;&lt;BR /&gt;&lt;BR /&gt;Here I need result for only xyz if it's present or not in count1 variable but my code is giving me result for all the records. I tried other few options as well but didn't work.</description>
      <pubDate>Sun, 03 Sep 2023 06:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892472#M39687</guid>
      <dc:creator>SBKH</dc:creator>
      <dc:date>2023-09-03T06:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Need to find if record is exist or not in input file through mainframe sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892474#M39688</link>
      <description>&lt;P&gt;Use a macro variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let found = 0;

data _null_;
infile inpt;
input @3 var1 char$3.;
if var1 ="xyz" then call symputx("found","1");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then use &amp;amp;found. in further code to decide what to do.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Sep 2023 08:08:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892474#M39688</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-03T08:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: Need to find if record is exist or not in input file through mainframe sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892475#M39689</link>
      <description>Thank you for the response !&lt;BR /&gt;I have used the code you have provided and later trying to write found record in o/p file&lt;BR /&gt;&lt;BR /&gt;Code I have added&lt;BR /&gt;File out_file;&lt;BR /&gt;Put @1 found;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;This gave me 12 • row wise in my o/p file as in my input file there are 12 records.</description>
      <pubDate>Sun, 03 Sep 2023 08:30:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892475#M39689</guid>
      <dc:creator>SBKH</dc:creator>
      <dc:date>2023-09-03T08:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Need to find if record is exist or not in input file through mainframe sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892505#M39691</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/450630"&gt;@SBKH&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you for the response !&lt;BR /&gt;I have used the code you have provided and later trying to write found record in o/p file&lt;BR /&gt;&lt;BR /&gt;Code I have added&lt;BR /&gt;File out_file;&lt;BR /&gt;Put @1 found;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;This gave me 12 • row wise in my o/p file as in my input file there are 12 records.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That does not make any sense in response to the answer that was marked as the solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That code did not create any variable named FOUND.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please explain what you are trying to do.&amp;nbsp; &amp;nbsp;Are you trying to create a DATASET?&amp;nbsp; Or are you trying to write a TEXT file?&amp;nbsp; If the later what type of TEXT file?&amp;nbsp; Just a plain listing/report file?&amp;nbsp; Are you trying to create a delimited file? Or a file with fixed length fields and fixed length records?&amp;nbsp; Or are you trying to create some other type of report file? Perhaps a PDF file or a sheet in an XLSX workbook?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It will help to include some small example input data and the output you expect to create from that input data.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2023 02:30:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892505#M39691</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-04T02:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: Need to find if record is exist or not in input file through mainframe sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892766#M39711</link>
      <description>I am new here and marked solution to the first answer as I accepted the answer by mistake.&lt;BR /&gt;&lt;BR /&gt;I'll try to add more details for my requirement here -&lt;BR /&gt;&lt;BR /&gt;I have input Fixed length PS input file&lt;BR /&gt;&lt;BR /&gt;ABC 123&lt;BR /&gt;DEF 567&lt;BR /&gt;GHI 879&lt;BR /&gt;XYZ 990&lt;BR /&gt;PQR 110&lt;BR /&gt;Here I need to find in my mainframe sas code if xyz is present in input file or not if it's present it should write a message in my output ps dataset as&lt;BR /&gt;Record found&lt;BR /&gt;If XYZ not ther 'Record not found '&lt;BR /&gt;&lt;BR /&gt;Below is the code I have written it's working perfectly if I only write condition to check record is present but not working when I try to check not present condition (getting multiple records)-&lt;BR /&gt;&lt;BR /&gt;Data inpt_fl;&lt;BR /&gt;Infile inpt_fl;&lt;BR /&gt;Input @3 jobname $char3.&lt;BR /&gt;@;&lt;BR /&gt;If jobname = 'xyz' then do ;&lt;BR /&gt;File out_pt;&lt;BR /&gt;Put 'record found';&lt;BR /&gt;End;&lt;BR /&gt;/* To check if the record presence&lt;BR /&gt;If index(jobname,'xyz') =0 then do;&lt;BR /&gt;Put 'Record not found ';&lt;BR /&gt;End;&lt;BR /&gt;Here I am getting 5 results with the below sequence&lt;BR /&gt;Record not found&lt;BR /&gt;Not found&lt;BR /&gt;Not found&lt;BR /&gt;Found&lt;BR /&gt;Not found.&lt;BR /&gt;&lt;BR /&gt;Because input file has 5 records but I want only one result i.e. if it's present it should print&lt;BR /&gt;Found and if it's not present then not found.&lt;BR /&gt;&lt;BR /&gt;Please help me to solve this riddle.&lt;BR /&gt;Thanks in advance!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 05 Sep 2023 16:19:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892766#M39711</guid>
      <dc:creator>SBKH</dc:creator>
      <dc:date>2023-09-05T16:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: Need to find if record is exist or not in input file through mainframe sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892769#M39712</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If by PS you mean a simple text file then it sounds like you want to read from one file and write to another file.&lt;/P&gt;
&lt;P&gt;If there some reason why you also want to make the SAS dataset?&amp;nbsp; If not then just use a date _NULL_ step instead of wasting time making a dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't seem to be reading the file you described in your question.&amp;nbsp; The file you showed looks like this:&lt;/P&gt;
&lt;PRE&gt;ABC 123
DEF 567
GHI 879
XYZ 990
PQR 110&lt;/PRE&gt;
&lt;P&gt;So it looks like you have a name in columns 1 to 3 (or possible also 4) and a number in columns 5 to 7.&lt;/P&gt;
&lt;P&gt;Which would translate to an INPUT statement like one of these.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input jobname $3. number ;
input jobname $ 1-3 number 5-7 ;
input jobname $3. +1 number 3. ;

input jobname $4. number 3.;
input jobname $ 1-4 number 5-7 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You need to keep track of whether or not you have found one yet so you only write one message.&amp;nbsp; You need to know when you have hit the end of the file to know when to write the not found message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So assuming you have either some JCL to define the DD names of INPT_FL and OUT_PT or you have previous SAS code with FILENAME statements define the filerefs of INPT_FL and the OUT_PT then your data step could look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data joblist;
  infile inpt_fl end=eof;
  file out_pt;
  if eof and not found then put 'Record not found';
  input jobname $3. number ;
  if lowcase(jobname) = 'xyz' then do ;
     found+1;
     put 'Record found';
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't need to make the dataset it is even easier since you can just stop when one is found.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data joblist;
  infile inpt_fl end=eof;
  file out_pt;
  if eof then put 'Record not found';
  input ;
  if lowcase(_infile_) =: 'xyz' then do ;
     put 'Record found';
     stop;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the JOBNAME field is actually longer than 4 bytes and you want to check if XYX appears anywhere in it then the IF condition can be modified to just use the INDEX() function to check if the substring exists.&amp;nbsp; Either in the JOBNAME variable or the whole input line.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if index(lowcase(jobname),'xyz') then do ;
if index(lowcase(_infile_),'xyz') then do ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2023 17:00:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892769#M39712</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-05T17:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: Need to find if record is exist or not in input file through mainframe sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892770#M39713</link>
      <description>&lt;P&gt;Should the message be in a dataset or a flat file?&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2023 17:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892770#M39713</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-05T17:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: Need to find if record is exist or not in input file through mainframe sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892860#M39717</link>
      <description>Thank you, This worked&lt;BR /&gt;Really appreciate your inputs here.</description>
      <pubDate>Wed, 06 Sep 2023 09:26:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892860#M39717</guid>
      <dc:creator>SBKH</dc:creator>
      <dc:date>2023-09-06T09:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: Need to find if record is exist or not in input file through mainframe sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892921#M39722</link>
      <description>Message should be in a dataset, I have given these input and output dasatates names in jcls&lt;BR /&gt;&lt;BR /&gt;I have one more query my code is not working specifically for record not found condition if I try to write multiple put conditions instead of only 'Record not found'&lt;BR /&gt;&lt;BR /&gt;On adding multiple puts it's giving me recurring results for each record</description>
      <pubDate>Wed, 06 Sep 2023 13:05:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892921#M39722</guid>
      <dc:creator>SBKH</dc:creator>
      <dc:date>2023-09-06T13:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need to find if record is exist or not in input file through mainframe sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892929#M39723</link>
      <description>Message should be in a dataset, I have given these input and output dasatates names in jcls&lt;BR /&gt;&lt;BR /&gt;I have one more query my code is not working specifically for record not found condition if I try to write multiple put conditions instead of only 'Record not found'&lt;BR /&gt;&lt;BR /&gt;On adding multiple puts it's giving me recurring results for each record</description>
      <pubDate>Wed, 06 Sep 2023 13:16:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892929#M39723</guid>
      <dc:creator>SBKH</dc:creator>
      <dc:date>2023-09-06T13:16:17Z</dc:date>
    </item>
    <item>
      <title>Re: Need to find if record is exist or not in input file through mainframe sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892931#M39724</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/450630"&gt;@SBKH&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Message should be in a dataset, I have given these input and output dasatates names in jcls&lt;BR /&gt;&lt;BR /&gt;I have one more query my code is not working specifically for record not found condition if I try to write multiple put conditions instead of only 'Record not found'&lt;BR /&gt;&lt;BR /&gt;On adding multiple puts it's giving me recurring results for each record&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Language is a tricky thing, words have multiple meanings.&amp;nbsp; Language in computer science is double tricky because normal words that have multiple meanings in other contexts are given very specific meanings (which may or may not be that close to the normal meanings) when used to discuss computers or computer languages.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To an old school IBM mainframe programmer a dataset is what a more modern programmer would call a simple file.&amp;nbsp; A series of lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To a SAS programmer a dataset is a special SAS specific structure that is used to store data.&amp;nbsp; It has variables and observations, not lines and columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS you read from the FILE using INFILE and INPUT statements.&amp;nbsp; You write to a file using FILE and PUT statements.&amp;nbsp; But you use a dataset using a SET/MERGE/UPDATE statement.&amp;nbsp; You create a dataset using a DATA statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So again which is it that you have as input?&amp;nbsp; A SAS dataset? If so then describe the dataset.&amp;nbsp; How many variables does it have? What are their names? Their types.&amp;nbsp; For the character variables their storage length? Do any of them have formats attached to them?&amp;nbsp; What formats? How many observations does it have.&amp;nbsp; You can get this information by running PROC CONTENTS on the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is it that you want to create?&amp;nbsp; A SAS dataset?&amp;nbsp; What variables should it have? What are their types? For character variables what are their storage lengths?&amp;nbsp; Do any of them need to have special display formats attached (normally only needed for date, time and datetime values)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the input is a FILE then what is its structure?&amp;nbsp; Does it have lines?&amp;nbsp; Does it used fixed length records? Or is it like a normal text file that uses variable length records that are ended by line termination characters?&amp;nbsp; How is the data on the lines organized?&amp;nbsp; Does it have values for different fields?&amp;nbsp; Are the fields fixed in length? Or do they vary from line to line?&amp;nbsp; If they vary how can you tell when one field ends and the next starts? Is a delimiter used between the fields on the line?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 13:28:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892931#M39724</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-06T13:28:09Z</dc:date>
    </item>
    <item>
      <title>Re: Need to find if record is exist or not in input file through mainframe sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892935#M39725</link>
      <description>Hi Tom,&lt;BR /&gt;I M not getting much on datasets that you are asking it's a mainframe PS output dataset where I need to write kind of a report where I have to provide jobnames and it's details like end time , completion time in tabular format,&lt;BR /&gt;Earlier I haven't provide these details because I thought I would be able to replace record found and not found messages to the message I want to write in output dataset.&lt;BR /&gt;But now when I try to add multiple put condition in record not found code is ignoring the first put line and remaining put statements are recurring which matches to the number of records.&lt;BR /&gt;&lt;BR /&gt;First code you have provided I have used that one....</description>
      <pubDate>Wed, 06 Sep 2023 13:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-to-find-if-record-is-exist-or-not-in-input-file-through/m-p/892935#M39725</guid>
      <dc:creator>SBKH</dc:creator>
      <dc:date>2023-09-06T13:33:34Z</dc:date>
    </item>
  </channel>
</rss>

