Check if input file record is sorted and if not it should abend - jcl

I'm trying to write a JCL that check if the input file record is sorted and if not it should abend with a specific message.
This is the job that I have; but I don't want it to sort anymore. I want it to abend if company number in column 3 not in Sequence;
//TOOL1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=T
//DFSMSG DD SYSOUT=T
//TOOLIN DD *
DATASORT FROM(INPUT1) TO(OUTPUT) HEADER TRAILER USING(CTL1)
/*
//INPUT1 DD DSN=FCGL.BPYP667.CNTL(GLGLJ010),
// DISP=SHR
//OUTPUT DD DSN=FCGL.BPYP667.CNTL(GLGLJ010),
// DISP=SHR,
// DCB=*.INPUT1
//CTL1CNTL DD *
SORT FIELDS=(3,4,CH,A)
/*

You can use a fake merge
(This is just a pseudo code of a fake merge, so please ignore any syntax errors if any),
//STEP1 EXEC PGM=SORT
//SORTIN DD DSN=YOUR-INP-DSN,DISP=SHR
//SORTOUT DD DSN=&&TEMP1,DISP=SHR
//SYSIN DD *
OUTREC=(1:3,1)
/*
//STEP2 EXEC PGM=SORT
//SORTIN01 DD DSN=&&TEMP1,DISP=SHR
//SORTOUT DD DUMMY or NULLFILE
//SYSIN DD *
MERGE FIELDS=COPY
/*
here STEP2 will fail if your input file not in sequence.
And as a 2nd option, In the JOINKEYS statement when the file is already sorted, we would give the SORTED Keyword if the file is already sorted. And if the records are not in the sorted order, it would terminate.

Related

How to display date as DD MMM YYYY imported from .csv

I have a service that picks up a .csv and processes it to .sas7bdat.
I modify an existing .sas template by filling in variable names, length, and specifying output location.
I have a scenario in which my .csv has a date formatted as 'DD MMM YYYY'. I need to preserve this format to the output file. The predefined formats allow for 'DDMMMYYY' and 'DD-MMM-YYYY'. I have tried these format types in the template.
Below is the template with standard character type:
LIBNAME TempSrc "C:\Temp";
proc import datafile="\\***\FileLocation\file.csv"
out=mydata dbms=dlm replace;
DELIMITER= ",";
getnames=yes;
options ExtendObsCounter=yes;
RUN;
DATA TempSrc.fileName;
attrib DATEVAR length=$11 format=$11. informat=$11. label='Date'
;
set work.mydata;
RUN;
How can I modify this code to output a date as follows '01 JAN 2000'
EDIT:
How can I output this value to the .sas7bdat as a character value?
There isn't a default format to display as DD MMM YYYY so it's necessary to roll your own. I believe the following gives you what you are trying to achieve:
proc format;
picture ddmmmyy
other= '%0d %b %Y' (datatype=date);
run;
data have;
datevar='01 JAN 2000';
run;
data want;
set have;
actualdatevar=input(datevar,anydtdte11.);
format actualdatevar ddmmmyy11.;
run;
gives:
Note that you cannot convert a character variable to numeric, so you may wish to create a new variable and then drop the old one (can also rename the new variable so that you end up with the same named variable).
EDIT1: to apply to specific answer (now situation is clearer)
The following should achieve what is needed:
LIBNAME TempSrc "C:\Temp";
proc format;
picture ddmmmyy
other= '%0d %b %Y' (datatype=date);
run;
proc import datafile="\\***\FileLocation\file.csv"
out=mydata dbms=dlm replace;
DELIMITER= ",";
getnames=yes;
options ExtendObsCounter=yes;
RUN;
/* if all you need to do is apply the format, you may be better using proc datasets */
DATA TempSrc.fileName;
set work.mydata;
format DATEVAR ddmmmyy11. ;
RUN;
EDIT2: converting to character so that it is displayed correctly in universal viewer (without the custom format)
LIBNAME TempSrc "C:\Temp";
proc format;
picture ddmmmyy
other= '%0d %b %Y' (datatype=date);
run;
proc import datafile="\\***\FileLocation\file.csv"
out=mydata dbms=dlm replace;
DELIMITER= ",";
getnames=yes;
options ExtendObsCounter=yes;
RUN;
/* convert numeric to character via rename */
DATA TempSrc.fileName;
set work.mydata (rename=(DATEVAR=DATEVAR2));
DATEVAR=put(DATEVAR2,ddmmmyy11.);
drop DATEVAR2;
RUN;

SAS: How to create dates out of month field, day field, and year field

I have the following script for inputting my data and creating a dataset.
data HotelRooms;
INFILE '/folders/myfolders/Hotel.dat' missover;
input RoomNo 1-4 NumbeGuests 7-8InMonth $ Inday $ InYear $ OutMonth $
OutDay $ OutYear $ UseWireless :$3. DaysUsed RoomType$53-68 RoomRate 69-71;
checkindate=CAT(InMonth,InDay,InYear);
checkoutdate=CAT(OutMonth, OutDay, OutYear);
If UseWireless='YES' then fee=9.95;
run;
proc print data=HotelRooms noobs;
format checkindate MMDDYY10.;
format checkoutdate MM/DD/YY/10.;
Run;
The data loads into the dataset just fine, but when I create a checkin date and a checkout date I run into issues. When I use CAT I cannot add a date format. The print does not print any / or - in the date, only mm dd yyyy. I will need to be able to use the dates for calculations also.
Any help will be appreciated.
Instead of reading your M/D/Y values as characters, read them as numbers and use the mdy() function to create a SAS date from the constituent parts :
data HotelRooms;
INFILE '/folders/myfolders/Hotel.dat' missover;
input RoomNo 1-4 NumbeGuests 7-8
InMonth Inday InYear
OutMonth OutDay OutYear
UseWireless :$3. DaysUsed RoomType $53-68 RoomRate 69-71;
checkindate = mdy(InMonth,InDay,InYear);
checkoutdate = mdy(OutMonth, OutDay, OutYear);
if UseWireless = 'YES' then fee = 9.95;
format checkindate checkoutdate mmddyy10. ;
run;
proc print data=HotelRooms noobs;
run;

Converting 10-digit char data to DB2 BIGINT-type using DFSORT

I want to convert a 10-digit character field which contains numeric data to an 8-byte binary to insert into a DB2 BIGINT field.
INPUT
-------
1531245800ABC
1531457890DEF
OUTPUT
-------
<8 byte numeric data>ABC
<8 byte numeric data>DEF
Load card
LOAD DATA
LOG NO
REPLACE
UNICODE CCSID(01208,00000,00000)
SORTDEVT SYSDA
SORTNUM 12
INTO TABLE
<TABLE-NAME>
KEEPDICTIONARY
(
QUOTEID POSITION (1)
BIGINT
,
GEO
POSITION ( 9 ) CHAR MIXED(3))
Using DFSORT symbols, to make things easier for you and future users:
//TOBIGINT EXEC PGM=SORT
//SYMNAMES DD *
INPUT-CHARACTER-NUMERIC,1,10,ZD
INPUT-CHARACTER-REST,*,3,CH
//SYMNOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC BUILD=(INPUT-CHARACTER-NUMERIC,
TO=BI,
LENGTH=8,
INPUT-CHARACTER-REST)
//SORTIN DD *
1531245800ABC
1531457890DEF
Or traditional coding of start, length, type:
//TOBIGINT EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC BUILD=(1,10,ZD,
TO=BI,
LENGTH=8,
11,3)
//SORTIN DD *
1531245800ABC
1531457890DEF
Output is X'000000005B44F4E8' followed by ABC and X'000000005B483162' followed by DEF.

How to load the db2 table from ps dataset using jcl utility DSNUTLIB?

I am using the JCL utility DSNUTLIB
And the JCL is,
//STEP01 EXEC PGM=DSNUTILB,
// REGION=0M
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSREC01 DD DSN=INPUTFILE.TEST,DISP=SHR
//SYSIN DD *
LOAD DATA
INDDN SYSREC01
REPLACE
INTO TABLE "table_schema.table_name"
( COL_1 POSITION(1) CHAR (8)
, COL_2 POSITION(9) CHAR (8)
, COL_3 POSITION(17) CHAR(200)
)
/*
When i am submiting the JCL i am geting SOC4E ana the error code = E40002.

Import date from a txt SAS

Currently I'm trying to import a .txt file to SAS, but I have one problem. The .txt I recieve has a columnthat looks this way
.......;2015/09/01 09:49;....
I need to import it as a date value not as a string. I've tryed many formats but none of them works correctly.
data aux;
infile "&LIBIN/&fichero" delimiter = ';' MISSOVER DSD lrecl=32767;
format fecha_mov .... ;
informat fecha_mov ....;
input
fecha_mov ;
run;
Thanks for the help in advanced,
Antonio,
The informat anydtdtm. works for me.
https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002605552.htm
data want;
infile cards dsd dlm=',';
informat dt anydtdtm.;
format dt datetime21.;
input dt;
cards;
2015/09/01 09:49
2015/09/01 08:49
2015/09/02 09:49
2015/09/05 09:49
;
run;
proc print;
run;
I would suggest using a more specific informat- that way if the source file ever changes unexpectedly, you remove the risk of the anydtdtm. format interpreting it incorrectly. If you use the : format modifier, you can ignore the time part and just use yymmdd10.:
data want;
infile cards dsd dlm=',';
input dt :yymmdd10. another_var $5.;
format dt yymmdd10.;
cards;
2015/09/01 09:49,dummy
2015/09/01 08:49,dummy
2015/09/02 09:49,dummy
2015/09/05 09:49,dummy
;
run;
proc print;
run;
N.B. if you don't use a : then SAS will not move the line pointer to the next delimiter character before starting to read in the next variable.