BookmarkSubscribeRSS Feed
thanikondharish
Fluorite | Level 6

given a data file with 100 observations of data, you only need to read in the first 70 columns 

8 REPLIES 8
PeterClemmensen
Tourmaline | Level 20
data have;
   do x=1 to 100;
      output;
   end;
run;

data want;
   set have(obs=70);
run;
thanikondharish
Fluorite | Level 6
I want variables not observations
PeterClemmensen
Tourmaline | Level 20

Ah ok. Do something like this

 

data have;
   array SomeArray{100} x1-x100;
run;

proc sql noprint;
   select name into :varnames separated by ' '
   from dictionary.columns
   where libname="WORK" and memname="HAVE" and varnum<=70
   order by varnum;
quit;

%put &varnames.;

data want;
   set have;
   keep &varnames.;
run;
thanikondharish
Fluorite | Level 6
It's good but how do we do using infile statement read only 70variables out
of 100 (is any options used like line,linesize,length
PeterClemmensen
Tourmaline | Level 20

What kind of data source do you want to read from with this infile statement? a .txt, .xlsx file? 

 

An infile statement is used to read data from an external file.

andreas_lds
Jade | Level 19

@thanikondharish wrote:
.xlsx file

Reading a named range is possible if you setup fits - there are some many papers and posts explaining this, i don't like to repeat it. If you don't have a range, you have to import everything and drop the unwanted variables.

PeterClemmensen
Tourmaline | Level 20

You cannot INFILE an XLSX file in DATA step.  You need to use an engine that can read the data structure of an Excel spreadsheet.

 

You can however import a .csv file with the INFILE Statement.

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1797 views
  • 0 likes
  • 3 in conversation