DATA Step, Macro, Functions and more

datalines, embedded tabs, interactive vs batch

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 78
Accepted Solution

datalines, embedded tabs, interactive vs batch

data here.knownSecType;

  input secType $;

  datalines;

  cmn

  option

  ;

run;

The 2 datalines each have 2 tab characters before the string.  When I run it interactively, the resulting dataset has no tabs in the secType field (e.g. "cmn").  When I run it in batch mode, I get tabs (e.g."        cmn").  Can anyone explain this?

(It's an issue because I'm helping a colleague develop some code and we want to work from one codebase.  He works interactively; I work in batch.  Subsequent joins with this table work for him and not for me.)lk


Accepted Solutions
Solution
‎05-01-2014 10:37 PM
Super User
Posts: 10,044

Re: datalines, embedded tabs, interactive vs batch

Add it :

data here.knownSecType;

  infile cards expandtabs;

  input secType $;

  datalines;

  cmn

  option

  ;

run;


Xia Keshan

View solution in original post


All Replies
Frequent Contributor
Posts: 78

Re: datalines, embedded tabs, interactive vs batch

I'm surprised no one has responded.  Too simple?  This kind of basic stuff sometimes vexes me.

Super User
Super User
Posts: 7,076

Re: datalines, embedded tabs, interactive vs batch

It does not convert the tabs on submission when using the old style PGM window in SAS 9.2 on a Unix machine.

17   data _null_;

18     input secType $;

19     list;

20   datalines;

RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0

21  CHAR   ..cmn

    ZONE   00666222222222222222222222222222222222222222222222222222222222222222222222222222

    NUMR   993DE000000000000000000000000000000000000000000000000000000000000000000000000000

22  CHAR   ..option

    ZONE   00677666222222222222222222222222222222222222222222222222222222222222222222222222

    NUMR   99F049FE000000000000000000000000000000000000000000000000000000000000000000000000

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

23   ;

24   run;

Are you using the "enhanced" editor? 

The "enhanced editor" will also honor the tab stops you have set in the options when converting these tabs to spaces.  So with tab stops set at 4 characters you get this:

2730  data _null_;

2731    input secType $;

2732    list;

2733  datalines;

RULE:       ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8---

2734                cmn

2735                option

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

2736  ;

2737  run

Frequent Contributor
Posts: 78

Re: datalines, embedded tabs, interactive vs batch

My colleague is the interactive one.  I'm 47 years old, so I use batch mode.  All that pointing and clicking bugs me.Smiley Wink

Trusted Advisor
Posts: 3,215

Re: datalines, embedded tabs, interactive vs batch

Jdmarino, the last reply about age is too tempting, you are still a youngster. I like the interactive approaches, the encoding challenges etc.
As you are using Notepad++ it also there with a nice indication for encoding. If you ever hit the BOM indicator you will see what I mean.
Strange the fixed 8 position translation with SAS. If you do this in notepad++ it are 4 positions, however you can change it to a personal value.   

---->-- ja karman --<-----
Solution
‎05-01-2014 10:37 PM
Super User
Posts: 10,044

Re: datalines, embedded tabs, interactive vs batch

Add it :

data here.knownSecType;

  infile cards expandtabs;

  input secType $;

  datalines;

  cmn

  option

  ;

run;


Xia Keshan

Frequent Contributor
Posts: 78

Re: datalines, embedded tabs, interactive vs batch

Worked like a charm.  I have to say, after I read the help on the infile statement (where the expandtabs option help is), there is no way I would have expected it to solve this problem, so your reply was valuable.  Thanks.

Trusted Advisor
Posts: 3,215

Re: datalines, embedded tabs, interactive vs batch

@jdmarino, As now you have been surprised by smart editor behavior. Just using old style Single-byte encoding.
Try this type of effects using UTF8 session encoding and more of those.   You will be really surprised.

---->-- ja karman --<-----
Frequent Contributor
Posts: 78

Re: datalines, embedded tabs, interactive vs batch

My colleague is the one who runs things interactively.  I use notepad++ to edit a file and run it in batch mode: no problems!

Super User
Super User
Posts: 7,076

Re: datalines, embedded tabs, interactive vs batch

Whatever editor you use I find that is causes problems to include tabs inside the program file.

In whatever editor you are using take advantage of the settings they have to convert the tabs to spaces. Most editors will let you do this. You can still use the tab key when typing to make things align but your saved files will not have those nasty tabs interspersed in random places in the text.

Frequent Contributor
Posts: 78

Re: datalines, embedded tabs, interactive vs batch

I agree.  And I do that (have my editor convert tabs to spaces).  And I wrote to my colleague to warn him that "tabs are EVIL".

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 524 views
  • 2 likes
  • 4 in conversation