BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
abcd123
Fluorite | Level 6

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

%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

6 REPLIES 6
DBailey
Lapis Lazuli | Level 10

perhaps you need to specify a different lrecl...

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

Tom
Super User Tom
Super User

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

Tom
Super User Tom
Super User

%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;

abcd123
Fluorite | Level 6

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?


LarryWorley
Fluorite | Level 6

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 ;


abcd123
Fluorite | Level 6

Thank you very much.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1495 views
  • 5 likes
  • 4 in conversation