View previous topic :: View next topic |
Author |
Message |
20cents Beginner
Joined: 26 Oct 2005 Posts: 25 Topics: 7 Location: Between Heaven and Hell
|
Posted: Wed Nov 09, 2005 3:53 am Post subject: SAS: How do I handle this? |
|
|
Hi,
Here's the scenario
1. I got 2 input files FileA and FileB;
2. I only need the header record from FileA;
3. I need all the data in FileB;
4. I need to produce a report:
SeqNo: XXXXXXX
CLASS NAME
-------- ------
YYYYYY YYYYY
YYYYYY YYYYY
YYYYYY YYYYY
XXXXXXX - is from FileA
YYYYYY - is from FileB
SeqNo is would serve as header for my report. FileB doesnt contain the data I need, so I need to get it from another File.
How do I tackle this?
20cents. |
|
Back to top |
|
|
vkphani Intermediate
Joined: 05 Sep 2003 Posts: 483 Topics: 48
|
Posted: Wed Nov 09, 2005 4:07 am Post subject: |
|
|
20cents,
I haven't understood anything from your scenarios.
What do you mean by this:
Quote: |
3. I need all the data in FileB;
FileB doesnt contain the data I need
|
|
|
Back to top |
|
|
20cents Beginner
Joined: 26 Oct 2005 Posts: 25 Topics: 7 Location: Between Heaven and Hell
|
Posted: Wed Nov 09, 2005 4:12 am Post subject: |
|
|
VK,
Sorry about that.
To make it clearer (i hope), all the columns that I need for my report resides on FileB, but for my report header (report title) I need to get it from FileA.
20cents. |
|
Back to top |
|
|
20cents Beginner
Joined: 26 Oct 2005 Posts: 25 Topics: 7 Location: Between Heaven and Hell
|
Posted: Wed Nov 09, 2005 4:22 am Post subject: |
|
|
I tried this:
DATA FDR;
INFILE FDRIN1;
INPUT @1 REC_TYPE $CHAR1.
@359 MAILCODE $CHAR2.
@359 BAG $CHAR17.
@361 BAG_ID $CHAR15.
@361 CENTER 2.
@363 PROD_ID $CHAR3.
@363 PROD_TYP $CHAR3.
@366 BANK_NUM 4.
@370 CARDTYPE 1.
@371 PRODTYP2 1.
@372 CARD_ISS 1.
@373 AIRMAIL 1.
@374 RESERV 2.;
JDATE = SUBSTR(SYSPARM(),1,3);
IF REC_TYPE = '5';
COUNT = 1;
INFILE FDRIN2 OBS=1;
INPUT @46 SEQ_NUM $CHAR8.;
My header worked fine... but then the body of my report also stopped on the first observation. |
|
Back to top |
|
|
batu544 Beginner
Joined: 02 Aug 2005 Posts: 75 Topics: 27
|
Posted: Wed Nov 09, 2005 5:11 am Post subject: |
|
|
20cents,
As per your example SEQ_NUM will be a new variable in this dataset FDR . and also you have given OBS=1. so it will read only the 1st observation. _________________ Regards,
batu |
|
Back to top |
|
|
batu544 Beginner
Joined: 02 Aug 2005 Posts: 75 Topics: 27
|
Posted: Wed Nov 09, 2005 5:46 am Post subject: |
|
|
can u give the exact input and desired output structure of your file. ?? _________________ Regards,
batu |
|
Back to top |
|
|
20cents Beginner
Joined: 26 Oct 2005 Posts: 25 Topics: 7 Location: Between Heaven and Hell
|
Posted: Wed Nov 09, 2005 7:16 pm Post subject: |
|
|
All,
thanks for the prompt reply.
Pls disregard my query above. But do help mw with this one.
How do I do this:
Table1 contains (one entry alone):
YYYYYYY
Table 2 contains:
1111111 ZZZZZZ XXXXXXX
2222222 RRRRRR TTTTTTTT
3333333 EEEEEEE QQQQQQ
4444444 UUUUUU MMMMMM
5555555 AAAAAA BBBBBBB
How do I merge the two tables (Table 1 and 2) and produce Table 3:
1111111 ZZZZZZ XXXXXXX YYYYYYY
2222222 RRRRRR TTTTTTTT YYYYYYY
3333333 EEEEEEE QQQQQQ YYYYYYY
4444444 UUUUUU MMMMMM YYYYYYY
5555555 AAAAAA BBBBBBB YYYYYYY
That's right! Append the value found in Table 1 to all rows in Table 2.
Your help is greatly appreciated. |
|
Back to top |
|
|
jetson Beginner
Joined: 07 Oct 2005 Posts: 30 Topics: 2 Location: Texas
|
Posted: Wed Nov 09, 2005 8:28 pm Post subject: |
|
|
proc sql;
create table table3 as
select * from table1, table2;
quit; |
|
Back to top |
|
|
20cents Beginner
Joined: 26 Oct 2005 Posts: 25 Topics: 7 Location: Between Heaven and Hell
|
Posted: Wed Nov 09, 2005 8:37 pm Post subject: |
|
|
batu544 wrote: | 20cents,
As per your example SEQ_NUM will be a new variable in this dataset FDR . and also you have given OBS=1. so it will read only the 1st observation. |
batu544,
You're right! that's what I wanted. I want to append a new column SEQ_NUM to the table FDR. SEQ_NUM would have the same values for all rows of the table FDR. The file where I get the value for SEQ_NUM contains a lot of un-needed data, and that the value of SEQ_NUM could only be found in the first observation, thus I limited it to OBS=1 for FDRIN2. But I want to read all the data from FDRIN1, which is also aborted due to the OBS=1 i coded in FDRIN2.
If you could see the post I made above, thats what I want to do.
20cents. |
|
Back to top |
|
|
20cents Beginner
Joined: 26 Oct 2005 Posts: 25 Topics: 7 Location: Between Heaven and Hell
|
Posted: Wed Nov 09, 2005 8:55 pm Post subject: |
|
|
jetson wrote: | proc sql;
create table table3 as
select * from table1, table2;
quit; |
Hi Jetson,
thanks for the reply.
Here's the two SAS datasets i want to combine:
DATA FDR;
INFILE FDRIN1;
INPUT @1 REC_TYPE $CHAR1.
@359 MAILCODE $CHAR2.
@359 BAG $CHAR17.
@361 BAG_ID $CHAR15.
@361 CENTER 2.
@363 PROD_ID $CHAR3.
@363 PROD_TYP $CHAR3.
@366 BANK_NUM 4.
@370 CARDTYPE 1.
@371 PRODTYP2 1.
@372 CARD_ISS 1.
@373 AIRMAIL 1.
@374 RESERV 2.;
DATA FDR2;
INFILE FDRIN2 OBS=1;
INPUT @46 SEQ_NUM $CHAR8.;
I want to append FDR2 to every record of FDR. how do I tackle this? |
|
Back to top |
|
|
jetson Beginner
Joined: 07 Oct 2005 Posts: 30 Topics: 2 Location: Texas
|
Posted: Wed Nov 09, 2005 9:07 pm Post subject: |
|
|
PROC SQL is the easiest way IMO. Since you are creating tables FDR and FDR2 using data steps, you can simply add the PROC SQL as the final step:
PROC SQL;
CREATE TABLE FDR3 AS
SELECT * FROM FDR, FDR2;
QUIT;
Also, as good programming practice, you should add a RUN; statement at the end of each data step. |
|
Back to top |
|
|
20cents Beginner
Joined: 26 Oct 2005 Posts: 25 Topics: 7 Location: Between Heaven and Hell
|
Posted: Wed Nov 09, 2005 9:22 pm Post subject: |
|
|
jetson wrote: | PROC SQL is the easiest way IMO. Since you are creating tables FDR and FDR2 using data steps, you can simply add the PROC SQL as the final step:
PROC SQL;
CREATE TABLE FDR3 AS
SELECT * FROM FDR, FDR2;
QUIT;
Also, as good programming practice, you should add a RUN; statement at the end of each data step. |
Hi Jetson,
thanks for the reply again. I encountered a problem.
The dataset created for FDR and FDR2 were WORK.FDR and WORK.FDR2 respectively. But the SQL statements are looking for WORK.FDR.DATA and WORK.FDR2.DATA.
Btw, could I use the newly created table as a normal SAS data set, like:
PROC SUMMARY DATA=FDR3;
BY BAG_ID;
ID CENTER PROD_ID CARDTYPE PROD_TYP PRODTYP2 JDATE SEQ_NUM;
VAR COUNT;
OUTPUT OUT=BAGRPT SUM=;
where FDR3 is the table created from the PROC SQL you've provided?
Many thanks to you.
20cents. |
|
Back to top |
|
|
jetson Beginner
Joined: 07 Oct 2005 Posts: 30 Topics: 2 Location: Texas
|
Posted: Wed Nov 09, 2005 10:02 pm Post subject: |
|
|
Can you post that section of the LOG? Did you put the PROC SQL step AFTER the two data steps?
Yes, PROC SQL CREATE TABLE creates a normal SAS dataset by default. |
|
Back to top |
|
|
20cents Beginner
Joined: 26 Oct 2005 Posts: 25 Topics: 7 Location: Between Heaven and Hell
|
Posted: Wed Nov 09, 2005 10:22 pm Post subject: |
|
|
Oh... IT WORKED!!! Thanks a lot Jetson... could I send you PMs incase i got more SAS questions.
/bows to Jetson |
|
Back to top |
|
|
jetson Beginner
Joined: 07 Oct 2005 Posts: 30 Topics: 2 Location: Texas
|
Posted: Wed Nov 09, 2005 10:44 pm Post subject: |
|
|
I've been a SAS programmer for 15 years. I'm no expert, but I've written a hell of a lot of SAS programs. Happy to help!
I'm new to this forum and I really like it. A great mainframe resource.
Kenny |
|
Back to top |
|
|
|
|