BookmarkSubscribeRSS Feed
jimksas
Calcite | Level 5

please help...

i have 100k obs datasets with 8 variables (reading from raw data file) and wants to know real length before it arrives into SAS (real length of raw data) How can i do that using sas code? I am not sure if PROC IMPORT wizard gives me correct length from raw file because have some field with leading zeros length more than 8 and by default import wizard is showing length 10 only....

2 REPLIES 2
Tom
Super User Tom
Super User

Read them in and figure it out. 

%let nvars=8 ;

data lengths ;

  length varnum 8 name $32 length 8 value $30000;

  array names (&nvars) $32 ;

  array lengths (&nvars) ;

  infile "myfile.csv" dsd truncover lrecl=30000  end=eof ;

  do varnum=1 to &nvars;

     input name @ ;

     names(varnum) = name ;

  end;

  input;

  do until (eof);

     do varnum = 1 to &nvars;

       input value @;

lengths(varnum)=max(lengths(varnum),length(value));

     end;

     input;

  end;

  do varnum=1 to &nvars;

    name=names(varnum);

    length=lengths(varnum);

    output;

    keep varnum name length;

  end;

run;

jimksas
Calcite | Level 5

Tom - i tried to run your code with my file in your infile statement - it is giving me;

- 3 variables : varnum/name/length

- only one value for name variable (only 1st obs)

- 43 length value for 1st obs -  all rest obs has same value  which is 1

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 837 views
  • 0 likes
  • 2 in conversation