-1

I am trying to read a data set that has columns like below:

1000 10001 1002 2000 2002 2004 2006
a    b     c    d    e    f    g
b    c     d    e    f    g    h

The format of the column names is number. I need to read this data and dynamically select the columns, say I want to read only columns 2000 to 2004.

pinegulf
  • 1,334
  • 13
  • 32
Arun Kumaar
  • 99
  • 1
  • 5
  • I don't know what you want exactly. But there are many ways to get variables dynamically. – Lee Mar 29 '19 at 07:12
  • Your question is not clear. Is this data in a SAS dataset? (I suspect not, SAS variable names can't be numeric). Is it in a text file that you are trying to read into a SAS dataset? What do you mean by dynamically select columns to be read? Also, show what code you have tried, and describe how it is not working. – Quentin Mar 29 '19 at 11:07

1 Answers1

0

If you will use proc import in SAS, it will automatically convert the numeric field names into character by adding "_"(underscore) prefix. Assuming that your file is tab delimited, then following simple code will work:

proc import datafile="Y:\Temp\numbers.txt" /*Name/Path of your text file*/
dbms=dlm
out=mydata
replace;
delimiter='09'x; /*Tab Delimiter*/
getnames=yes;
run;

proc print data=mydata; run;

You will get following output:

enter image description here

Once, you have your desired dataset, then you can keep/drop required variables.

Rhythm
  • 680
  • 5
  • 9