Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Basic Input statement - SAS

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics
View previous topic :: :: View next topic  
Author Message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1445
Location: Azeroth

PostPosted: Mon Jul 16, 2012 8:32 pm    Post subject: Basic Input statement - SAS
Reply with quote

Hello,
There is a SAS program,
Code:
DATA WELLS;           
INFILE CARDS DLM=', ';
INPUT (VAR1-VAR4) ($);
CARDS;               
A1,                   
B2,C3,               
D4                   
E1,F2,               
G3,H4                 
A1,B2,C3,             
D4                   
;                     
RUN;                 

This program quietly reads data and produces a nice output like below,
Code:
VAR1    VAR2    VAR3    VAR4
                           
 A1      B2      C3      D4
 E1      F2      G3      H4
 A1      B2      C3      D4


But if the data has embedded spaces in them then comes the problem.
Could someone please let me know how to read the below data into 4 variables.
Code:
A 1,     
B 2,C3,   
D4       
E 1,F2,   
G3,H 4   
A1,B 2,C3,
D 4       

Expected output:
Code:

VAR1    VAR2    VAR3    VAR4
                           
 A 1     B 2     C3      D4
 E 1     F2      G3      H 4
 A1      B 2     C3      D 4


I could try @@ but that maybe overkill.

Thanks in advance,
Back to top
View user's profile Send private message

expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Mon Jul 16, 2012 9:10 pm    Post subject:
Reply with quote

Have you tried INFILE CARDS DLM=', ' DSD;
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1445
Location: Azeroth

PostPosted: Mon Jul 16, 2012 10:54 pm    Post subject:
Reply with quote

Hi Expat,
Tried DSD but did'nt work. Some values are not read into variables correctly.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Mon Jul 16, 2012 11:01 pm    Post subject:
Reply with quote

Well really Vasanthz, you have not posted the actual output to compare against the expected output, now go stand in the naughty corner icon_lol.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Jul 16, 2012 11:23 pm    Post subject:
Reply with quote

EXPAT wrote:
you have not posted the actual output to compare against the expected output,

you mean to allow for intuitive analysis of what is going on?
EXPAT, you expect to much.
Vsanathz, you are a much better technician than your post implies.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Mon Jul 16, 2012 11:26 pm    Post subject:
Reply with quote

Vasanthz, the & (ampersand) format modifier is a possibility. However, as this page indicates the requirement is for variables to be separated by at least two spaces: Reading embedded spaces with SAS
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Tue Jul 17, 2012 12:11 am    Post subject:
Reply with quote

dbzTHEdinosauer wrote:

Vsanathz, you are a much better technician than your post implies.

Good spot Dick, my comments made were somewhat tongue in cheek
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1445
Location: Azeroth

PostPosted: Tue Jul 17, 2012 12:14 am    Post subject:
Reply with quote

Hi,
Thanks all in trying to help :-)
My bad. I forgot to copy paste the output which I got when I ran the program with 2nd set of data(possible culprit - hangover or lucid dreaming).
I will post it tomorrow when im at work.

Robert, & is a nice idea, I will try it out to see if I am able to get it working.

Regards,
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1445
Location: Azeroth

PostPosted: Tue Jul 17, 2012 12:41 am    Post subject:
Reply with quote

Hello,
I powered my PC SAS and tested Robert's suggestion. But SAS seems to ignore the comma as delimited when I tried "&".

Here are some of the things I tried out,
Code:

Expected output:
VAR1    VAR2    VAR3    VAR4
                           
 A 1     B 2     C3      D4
 E 1     F2      G3      H 4
 A1      B 2     C3      D 4

For the statement,
INFILE CARDS DLM=', ';
output was,
                                 Obs    VAR1    VAR2    VAR3    VAR4

                                  1      A       1       B       2
                                  2      D4      E       1       F2
                                  3      G3      H       4       A1

For
INFILE CARDS DLM=', ' DSD;
output:
                                 Obs    VAR1    VAR2    VAR3    VAR4

                                  1      A       1
                                  2      B       2       C3
                                  3      D4
                                  4      E       1       F2
                                  5      G3      H       4
                                  6      A1      B       2       C3
                                  7      D       4

For
INFILE CARDS DLM=',' ;
INPUT (VAR1-VAR4) (& $) ;
Output:
                              Obs    VAR1     VAR2      VAR3      VAR4

                               1     A 1               B 2,C3
                               2     D4      E 1,F2              G3,H 4

For
INFILE CARDS DLM=', ' ;
INPUT (VAR1-VAR4) (& $) ;
Output:
                               Obs    VAR1     VAR2     VAR3     VAR4

                                1     A 1     B 2,C3     D4     E 1,F2


Quote:
Vsanathz, you are a much better technician than your post implies.
Thanks for the compliment/pun (:
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jul 17, 2012 2:16 am    Post subject:
Reply with quote

was not a pun, it is a statement of fact.

you know that one can not even start to 'debug' until
one knows what is happening.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Tue Jul 17, 2012 12:12 pm    Post subject:
Reply with quote

Try this :
Code:

INFILE CARDS DLM=',';
INPUT (VAR1-VAR4) ($8.);
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1445
Location: Azeroth

PostPosted: Tue Jul 17, 2012 1:49 pm    Post subject:
Reply with quote

Hello Peter, I tried out your suggestion.
Code:
INFILE CARDS DLM=',';   
INPUT (VAR1-VAR4) (:$8.);

here is the output,
Code:

VAR1    VAR2    VAR3    VAR4
                           
 A1              B2      C3
 D4      E1      F2         
 G3      H4      A1      B2


The problem I think is, for the record
A 1,
SAS reads A1 into VAR1 and when it encounters "," it reads the spaces into VAR2.
I could supress this behavior by mentioning spaces in DLM like
DLM='<space>,'. But mentioning space in DLM option causes incorrect reading of data with embedded spaces in them.

To test if this is the case,
I ran the below program with FB files and VB files.
INFILE 'WELLS.EXTERNAL.FILE.' DLM=',';
INPUT (VAR1-VAR4) ($);

For VB external file the output was same as expected output,
Code:
VAR1    VAR2    VAR3    VAR4
                           
A 1     B 2      C3     D4 
E 1     F2       G3     H 4
A1      B 2      C3     D 4


For FB external file the output was not correct due to trailing blanks.
Code:
VAR1    VAR2    VAR3    VAR4
                           
A 1             B 2     C3 
D4      E 1     F2         
G3      H 4     A1      B 2

So I guess I will copy the whole file into a VB file and then process it.
If there are any other alternative please let me know.

Thank you,
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Tue Jul 17, 2012 2:01 pm    Post subject:
Reply with quote

(:$8.); was not in my sample.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1445
Location: Azeroth

PostPosted: Tue Jul 17, 2012 2:38 pm    Post subject:
Reply with quote

Peter, Thank you in trying to help.
I assumed you meant (:$8.) instead of ($8.) since this was list input.

Because if we read a delimited file using list input without a format modifier ($8.) then input statement will ignore the delimiter specified in DLM option and read 8 bytes of data even if it encounters a delimiter.

without format modifier:
Code:
DATA wells;             
INFILE CARDS DLM=',';   
INPUT VAR1 $8. VAR2 $8.;
CARDS;                   
1,3                     
AB,4                     
;                       
RUN;                     

output:
Code:
Obs    VAR1    VAR2
                   
 1     1,3         
 2     AB,4       

With format modifier:
Code:
DATA wells;               
INFILE CARDS DLM=',';     
INPUT VAR1 :$8. VAR2 :$8.;
CARDS;                   
1,3                       
AB,4                     
;                         
RUN;                     

Output:
Code:

Obs    VAR1    VAR2
                   
 1      1       3 
 2      AB      4 
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Tue Jul 17, 2012 2:41 pm    Post subject:
Reply with quote

Yes, you are totally right.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Tue Jul 17, 2012 4:00 pm    Post subject:
Reply with quote

Haven't got access to try this but maybe you could icon_biggrin.gif

It's a variation of code that I have used for processing a .csv file, and all I have done is remove the TRUNCOVER from the infile as you are not using a formatted .csv per se as your input, so without either of the MISSOVER or TRUNCOVER options specified should fill the obs as you want it.

Code:
  INFILE FILE1 DLM="," ;
  INPUT N1:$8.
        N2:$8.
        N3:$8.
        N4:$8. ;
RUN;
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1445
Location: Azeroth

PostPosted: Wed Jul 18, 2012 9:54 am    Post subject:
Reply with quote

Hello Expat,
Still no joy with the code, here is the output of the above code,
Code:
N1          N2          N3     N4
                                 
A 1                     B 2    C3
D4          E 1         F2       
G3          H 4         A1     B 2


Input:
Code:

A 1,     
B 2,C3,   
D4       
E 1,F2,   
G3,H 4   
A1,B 2,C3,
D 4       

Regards,
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Wed Jul 18, 2012 12:49 pm    Post subject: Reply to: Basic Input statement - SAS
Reply with quote

Maybe it is a "philosophical" thing. Where you have a trailing comma, the implication (being made by SAS) is that you have another field containing a blank.

In fact, if you did have a final field that could contain a blank, that is how you'd want SAS to behave.

Whether the behaviour can be modified, I have no idea.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1445
Location: Azeroth

PostPosted: Wed Jul 18, 2012 2:09 pm    Post subject:
Reply with quote

Yes Bill, It seems to be the way SAS was designed. As a temporary workaround, I have copied the data to VB file and processed it until alternative way is found.
Quote:
Whether the behaviour can be modified, I have no idea.

Me too
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 24 Tue Dec 06, 2016 8:04 pm
No new posts High CPU consumption Job using IAM fi... aswinir JCL & VSAM 8 Thu Dec 01, 2016 8:28 pm
No new posts -913/-911 Deadlock during UPDATE stat... NoSleep319 DB2 5 Fri Nov 18, 2016 12:37 am
This topic is locked: you cannot edit posts or make replies. How to use 2 input files in control c... Gunapala CN DFSORT/ICETOOL 23 Thu Oct 13, 2016 3:42 pm
No new posts COBOL DB2 - CALL statement - high CPU... TS70363 DB2 15 Sun Sep 11, 2016 6:07 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us