Desktop productivity for business analysts and programmers

informat $varying10. length-variable

Accepted Solution Solved
Reply
Super Contributor
Super Contributor
Posts: 340
Accepted Solution

informat $varying10. length-variable

Hi guys i am trying to read below data with 3 variables (ssn (length=11), name(length=8), satscore(length=3)) but i am not perfectly getting right values for "satscrore" variable plz help...

Thanks!

data test2 (drop=namelen);

infile cards length=reclen;

input ssn $11. @;

namelen=reclen-14;

input name $varying8. namelen satscore;

cards;

182-04-7814aspden530

302-57-5067atwood480

152-45-5678cutchins790

302-57-1234brosp560

;

run;


Accepted Solutions
Solution
‎11-27-2013 05:21 PM
Respected Advisor
Posts: 3,788

Re: informat $varying10. length-variable

CARDS data is, well, like cards FIXED length.  If you want an in-stream file that is variable lenght you can use PARMCARDS.  These data are loaded into an actual file.

filename FT15F001 temp;
data test2;* (drop=nameen);
  
infile FT15F001 length=reclen;
   input ssn $11. @;
   namelen=reclen-14;
  
input name $varying8. namelen satscore;
   parmcards;
182-04-7814aspden530
302-57-5067atwood480
152-45-5678cutchins790
302-57-1234brosp560
;;;;
   run;
proc print;
  
run;

View solution in original post


All Replies
Respected Advisor
Posts: 3,156

Re: informat $varying10. length-variable

I haven't dug deep enough to find the related Docs, but my guess is length= is only work with external files, not with cards/datalines (fixed length of 80 will be assigned),  So you have to get it yourself:

data test2 (drop=namelen reclen);

infile cards;

input ssn $11. @;

reclen=length(_infile_);

namelen=reclen-14;

input name $varying8. namelen satscore;

cards;

182-04-7814aspden530

302-57-5067atwood480

152-45-5678cutchins790

302-57-1234brosp560

;

run;

Haikuo

Solution
‎11-27-2013 05:21 PM
Respected Advisor
Posts: 3,788

Re: informat $varying10. length-variable

CARDS data is, well, like cards FIXED length.  If you want an in-stream file that is variable lenght you can use PARMCARDS.  These data are loaded into an actual file.

filename FT15F001 temp;
data test2;* (drop=nameen);
  
infile FT15F001 length=reclen;
   input ssn $11. @;
   namelen=reclen-14;
  
input name $varying8. namelen satscore;
   parmcards;
182-04-7814aspden530
302-57-5067atwood480
152-45-5678cutchins790
302-57-1234brosp560
;;;;
   run;
proc print;
  
run;
🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 211 views
  • 1 like
  • 3 in conversation