Help using Base SAS procedures

why cards stop reading values at some length

Accepted Solution Solved
Reply
Contributor
Posts: 51
Accepted Solution

why cards stop reading values at some length

Hello, All

I have following code (which is very similar to my real work):

%let string=0=Emergency Services, 1=Tele Call, 2=Cusstomet Answer, 3=TAB, 4=Ptt Mute Voice, 5=Com User Voice Control, 6=Com System User Call, 7=ABC, 8=Disc, 9=XYZ, 10=Exe News, 11=ABC Ext Source, 12=MNGFR Com and BFC MUYH, 13=Not Req;

data test;

infile cards delimiter="=," ;

    length var $ 30;

    input @@;

    _infile_ = resolve(_infile_);

    input var @@;

cards;

&string

;

proc print data=test;

run;

The code runs ok; however the result is kind of strange; there is only 10 rows in the result:

Obsvar

  10
  2Emergency Services
  31
  4Tele Call
  52
  6Cusstomet Answer
  73
  8TAB
  94
10Ptt Mute Voice

Why does the code stop reading at Ptt Mute Voice ?


Accepted Solutions
Solution
‎07-24-2013 12:30 PM
Super User
Super User
Posts: 6,499

Re: why cards stop reading values at some length

%let string=0=Emergency Services, 1=Tele Call, 2=Cusstomet Answer, 3=TAB, 4=Ptt Mute Voice, 5=Com User Voice Control, 6=Com System User Call, 7=ABC, 8=Disc, 9=XYZ, 10=Exe News, 11=ABC Ext Source, 12=MNGFR Com and BFC MUYH, 13=Not Req;

filename junk temp;

data _null_;

  file junk lrecl=40000;

  put "&string";

run;

data test;

  infile junk delimiter="=," lrecl=40000;

  length var $100 ;

  input var @@;

  put var;

run;

View solution in original post


All Replies
Super Contributor
Posts: 578

Re: why cards stop reading values at some length

perhaps you need to specify a different lrecl...

infile cards delimiter="-," lrecl=1000 recfm=v;

Super User
Super User
Posts: 6,499

Re: why cards stop reading values at some length

Because you cannot modify the lrecl of the input stream that SAS is using to read the code.

Solution
‎07-24-2013 12:30 PM
Super User
Super User
Posts: 6,499

Re: why cards stop reading values at some length

%let string=0=Emergency Services, 1=Tele Call, 2=Cusstomet Answer, 3=TAB, 4=Ptt Mute Voice, 5=Com User Voice Control, 6=Com System User Call, 7=ABC, 8=Disc, 9=XYZ, 10=Exe News, 11=ABC Ext Source, 12=MNGFR Com and BFC MUYH, 13=Not Req;

filename junk temp;

data _null_;

  file junk lrecl=40000;

  put "&string";

run;

data test;

  infile junk delimiter="=," lrecl=40000;

  length var $100 ;

  input var @@;

  put var;

run;

Contributor
Posts: 51

Re: why cards stop reading values at some length

Thank you very much. Really appreciate you spending time helping me.

Just one more question: if I include that long list directly in the Cards, it works; i.e.:

data test;

infile cards delimiter="=," ;

    length var $ 30;

    input var @@;

cards;

0=Emergency Services, 1=Tele Call, 2=Cusstomet Answer, 3=TAB, 4=Ptt Mute Voice, 5=Com User Voice Control, 6=Com System User Call, 7=ABC, 8=Disc, 9=XYZ, 10=Exe News, 11=ABC Ext Source, 12=MNGFR Com and BFC MUYH, 13=Not Req

;


So I guess the "lrecl of the input stream that SAS is using" means something SAS use internally?


Frequent Contributor
Posts: 129

Re: why cards stop reading values at some length

Methinks you have discovered some artifacts left over from the ancient days when cards statement really meant physical cards with an lrecl of 80.  Looks to me like the assignment of a value to _infile_ is limited to 80 character, but when done by reading input buffer, the limit is not applied.

I would consider scanning a character variable with the string value in it, rather than trying to get the cards statement to work.  Something like this would work and perhaps be a little more transparent to a maintenance program later on:

%let string=0=Emergency Services, 1=Tele Call, 2=Cusstomet Answer, 3=TAB, 4=Ptt Mute Voice, 5=Com User Voice Control, 6=Com System User Call, 7=ABC, 8=Disc, 9=XYZ, 10=Exe News, 11=ABC Ext Source, 12=MNGFR Com and BFC MUYH, 13=Not Req;

data test;

string = "&string";
i_scan = 1 ;
do until (scan(string,i_scan,",=") = '') ;
    var = scan(string,i_scan,",=") ;
    output ;
     put _n_= var= ;
     i_scan + 1 ;
  end ;
run ;


Contributor
Posts: 51

Re: why cards stop reading values at some length

Thank you very much.

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 339 views
  • 3 likes
  • 4 in conversation