Write and run SAS programs in your web browser

Creating a Raw Data file

Reply
Contributor
Posts: 45

Creating a Raw Data file

I used the following code and when I submitted, my raw data file is not in the proper order as I expected. I even used the word wrap but no use. What can be the solution?

Attachment
Contributor
Posts: 45

Re: Creating a Raw Data file

 
Attachment
Grand Advisor
Posts: 16,296

Re: Creating a Raw Data file

Please post your code as text...I don't want to type it out to replicate your issue. 

 

I'm fairly certain the export is fine, your text editor is muddling it up for some reason. 

Try NotePad ++ instead perhaps.

 

Contributor
Posts: 45

Re: Creating a Raw Data file

data _null_;
set sasuser.stress;
file '/folders/myshortcuts/Desktop/stress.txt';
put ID $ 1-4 Name $ 6-25 RestHR 27-29 MaxHR 31-33 RecHR 35-37
TimeMin 39-40 TimeSec 42-43 Tolerance $ 45;
run;
SAS Super FREQ
Posts: 8,642

Re: Creating a Raw Data file

Try opening your file with Word and see whether the Unix carriage return/line feeds are respected. That is one suggestion, there is another option that you specify that you use TERMSTR=CRLF on the FILE statement as an option to have a PC carriage return/linefeed written out for the end of record mark. Check the Unix documentation for value of TERMSTR=.

cynthia
Valued Guide
Posts: 505

Re: Creating a Raw Data file

This should show you exactly what is in the raw file.

0D0A is end of record windows CR/LF
0A is Unix end of record

It makes a difference it you ar erunning on Unix or Windows

HAVE A RAW FILE WITH BAD HEX CODES ( 0A and 0D for instance)

file c:/txt/badhex.txt

The records look fine in the log window

   AAAAAAAAAAA
BBBBBB

   AAAAAAAAAAA
BBBBBB

   AAAAAAAAAAA
BBBBBB




WANT ( A lising like this to see the bad characters like 0A and 0D in the data


 RULE:     ----+----1----+----2----+----3----+-

 1   CHAR  AAAAAAAAAAA.BBBBBB..
     ZONE  44444444444044444400
     NUMR  11111111111A222222DA

 2   CHAR  AAAAAAAAAAA.BBBBBB..
     ZONE  44444444444044444400
     NUMR  11111111111A222222DA

 3   CHAR  AAAAAAAAAAA.BBBBBB..
     ZONE  44444444444044444400
     NUMR  11111111111A222222DA


SOLUTION

* create a bad file;
data _null_;
  file "c:/txt/badhex.txt" lrecl=20 recfm=f;
   do i=1 to 3;
     txt=cats(repeat('A',10),'0A'X,repeat('B',5),'0D0A'X);
     put txt;
     putlog txt;
   end;
run;quit;

* just pick and lrecl and recfm that is close to what your record length is and
  use the code below. Then look for bad chars;

data _null_;
  infile "c:/txt/badhex.txt" recfm=f lrecl=20;
  input r20 $char20.;
  list;
run;quit;

 NOTE: The infile "c:/txt/badhex.txt" is:
       Filename=c:\txt\badhex.txt,
       RECFM=F,LRECL=20,File Size (bytes)=60,
       Last Modified=22Aug2016:13:31:11,
       Create Time=22Aug2016:13:24:00

 RULE:     ----+----1----+----2----+----3----+-

 1   CHAR  AAAAAAAAAAA.BBBBBB..
     ZONE  44444444444044444400
     NUMR  11111111111A222222DA

 2   CHAR  AAAAAAAAAAA.BBBBBB..
     ZONE  44444444444044444400
     NUMR  11111111111A222222DA

 3   CHAR  AAAAAAAAAAA.BBBBBB..
     ZONE  44444444444044444400
     NUMR  11111111111A222222DA


A better way is to use the old text editor and 'proc fslist'.
However this does not work well or at all in
(EE,EG,UE,SAS Studio)

filename fsl "c:\txt\badhex.txt' lrecl=20 recfm=f;
proc fslist file=fsl;
run;quit;

When the full screen editor comes up, you will need
a nice command line. This is where all the other editors fail.

On the command line type nums on;hex on;

You can use quite a few of the old text editor scripting commands
like find '0A'X;

Post a Question
Discussion Stats
  • 5 replies
  • 232 views
  • 2 likes
  • 4 in conversation