comp.soft-sys.sas - The SAS statistics package.
Hi, This is the code I have made to traverse a file and write the first 4 records out to another file: filename in 's:\fremkon\r20-prel.dat'; filename out 'D:\TEST\fixed_files\out.dat'; %let num_rec = 4; *number of records to write; %let rl = 65; *record length; data _null_; infile in lrecl=&rl recfm=v; file out lrecl=&rl recfm=v pad; input; if _n_ <= &num_rec then ; do; *removing crlf that are disturbing SAS; if length(_infile_) < &rl then do; _infile_=tranwrd(_infile_,'0d0a'x," "); end; put _infile_; end; run; The SAS log doesn't seem to agree with the logic I had in mind when I wrote the code: 22 filename in 's:\fremkon\r20-prel.dat'; 23 filename out 'D:\TEST\fixed_files\out.dat'; 24 %let num_rec = 4; *number of records to write; 25 %let rl = 65; *record length; 26 27 data _null_; 28 infile in lrecl=&rl recfm=v; 29 file out lrecl=&rl recfm=v pad; 30 input; 31 if _n_ <= &num_rec then ; 32 do; 33 *removing crlf that are disturbing SAS; 34 if length(_infile_) < &rl then 35 do; 36 _infile_=tranwrd(_infile_,'0d0a'x," "); 37 end; 38 put _infile_; 39 end; 40 run; NOTE: The infile IN is: File Name=s:\fremkon\r20-prel.dat, RECFM=V,LRECL=65 NOTE: The file OUT is: File Name=D:\TEST\fixed_files\out.dat, RECFM=V,LRECL=65 NOTE: 423554 records were read from the infile IN. The minimum record length was 0. The maximum record length was 65. NOTE: 423554 records were written to the file OUT. The minimum record length was 65. The maximum record length was 65. NOTE: DATA statement used (Total process time): real time 2.12 seconds cpu time 1.10 seconds --- Why are not just 4 records written to the file OUT ? Regards Rune Runnest
Hello SAS-Ls, I have a large dataset, about 20,000 data, and I need randomly select just 400 of it. How do I use ranuni to retrieve only 400 data? Thanks a lot. Jane
dataset1 name ID Gender Jack 18 M B 20 F D 10 F E 20 F Mike 18 M F 20 F H 10 F L 20 F Dataset2 State Label City IA 18 M GA 20 F LA 10 F NC 20 F How to write a program to create a dataset "Search" where hold the records where the value of label in dataset 2 equal the value of ID in dataset1. The variables in the new datasets are Name, Label, and City.
Hi, In the example below, I try to fix a dislocation in a file. The file have a dislocation i records # 4, 8 and 13. filename wrong 'd:\wrong.dat'; filename right 'd:\rigth.dat'; data _null_; file wrong recfm=f lrecl=34; put '123456789012345678901234567890-a '; put '123456789012345678901234567890-b '; put '123456789012345678901234567890-c '; put '1234567890 12345678901234567890-d '; *rec# 4; put '123456789012345678901234567890-e '; put '123456789012345678901234567890-f '; put '123456789012345678901234567890-g '; put '1234567890 12345678901234567890-h '; *rec# 8; put '123456789012345678901234567890-i '; put '123456789012345678901234567890-j '; put '123456789012345678901234567890-k '; put '123456789012345678901234567890-l '; put '1234567890 12345678901234567890-m '; *rec# 13; run; data _null_; infile wrong recfm=f lrecl=33; file right recfm=f lrecl=33; input; if _n_ = 4 then do; substr(_infile_,11) = substr(_infile_,12); end; put _infile_; run; The result is not what I expect. First, 14 rather than 13 records are read from wrong.dat. Second, there is a change in the file, but not the one I wanted. What is wrong with this code ? Regards Rune Runnest