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:
Obs | var |
1 | 0 |
2 | Emergency Services |
3 | 1 |
4 | Tele Call |
5 | 2 |
6 | Cusstomet Answer |
7 | 3 |
8 | TAB |
9 | 4 |
10 | Ptt Mute Voice |
Why does the code stop reading at Ptt Mute Voice ?
%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;
perhaps you need to specify a different lrecl...
infile cards delimiter="-," lrecl=1000 recfm=v;
Because you cannot modify the lrecl of the input stream that SAS is using to read the code.
%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;
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?
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 ;
Thank you very much.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.