BookmarkSubscribeRSS Feed
thanikondharish
Calcite | Level 5

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
Calcite | Level 5
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
Calcite | Level 5
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.

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!

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.

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
  • 8 replies
  • 759 views
  • 0 likes
  • 3 in conversation