0
votes

I have 2 different delimited files (csv and text) having the variables below respectively. The first 3 are character variables and the rest are numeric variables:Plant, Type, Treatment, conc, uptake. the text file has 5 numeric variables and a character variable.I would like to import the two files using a macro variable for every delimiter in SAS as part of an exercise. I have the code below to extract multiple files using macro. I would like to get your advice on how to create a macro variable for every delimiter (csv, text).

%macro one (output, Sample);

proc import out=output

datafile= "C:\Users\komal\Desktop\Sample.csv"

dbms=csv replace;

getnames=yes;

run;

%mend one;

%one (output, Sample.csv);
%one (data2, datafiletwo.txt);
2
Please clarify: Your first file is a Comma Separated Value File, hence %one (output, Sample.csv);, but you say your second file is a text file and you write %one (data2, datafiletwo.xlsx);, apparently refering an excel workbook.Dirk Horsten
The second file is a txt file and not excel file. It is just an example.K Bh

2 Answers

1
votes

You import different type of data, so you need to define type of data in dbms.

%macro one (output, Sample,type);
    proc import out=&output
    datafile= "C:\Users\komal\Desktop\&Sample"
    dbms=&type replace;
    getnames=yes;
    run;
%mend one;

%one (output, Sample.csv,cvs);
%one (data2, datafiletwo.xlsx,excel);
%one (class, class.txt,tab);
0
votes

Thanks Shenglin

I have tried the code below and it works perfectly.

    %macro one (a, b, c);
    proc import out=&a
    datafile= "C:\Users\komal\Desktop\&b"
    dbms=&c replace;
    getnames=yes;
    run;
%mend one;

%one (outcsv, Sample.csv, csv);
%one (outtab, datafiletwo.txt, tab);