BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rakkoo
Fluorite | Level 6

Hello. Would you please help me? I'm a beginner in the world of macro.

I have downloaded about 300 raw data files, monthly data between 1989 and 2013. I need only about 10 variables in each file. I have the list of the physical names of all the raw data files. Then, I have to create a new data file for each month. For example,

RAW DATA                                  NEW DATA

c:\cps\cpsb91\cpsb9111      -->      c:\cps\replicate\d199111.sas7bdat

c:\cps\cpsb91\cpsb9112      -->      c:\cps\replicate\d199112.sas7bdat

c:\cps\cpsb92\cpsb9201      -->      c:\cps\replicate\d199201.sas7bdat

c:\cps\cpsb92\cpsb9202      -->      c:\cps\replicate\d199202.sas7bdat

c:\cps\cpsb92\cpsb9203      -->      c:\cps\replicate\d199203.sas7bdat

. . . and so forth

So, I thought I had to use MACRO. The problem that I cannot solve is that the program below works beautifully only if the raw data file has no extension, such as ".dat"

______________________________________________________________________

libname replicat 'c:\cps\replicate';

%macro CPSMACRO/parmbuff;

%let i=1;

%let m=6;

%let y=1995;

%let prfx=d;

%let raw=%scan(&syspbuff,&i);

%do %while(&raw ne);

%let yyyymm=%eval(&y*100+&m);

%let fname=&prfx.&yyyymm;

data replicat.&fname.;

infile &raw. lrecl=2300 missover;                        <-- In this INFILE statement, I include the macro variable.

input

@1 hh 15.

@122 age 2.

@436 ind $3.

@439 occu $3.

;

run;

%if &m=12 %then %do;

  %let i=%eval(&i+1);

  %let m=1;

  %let y=%eval(&y+1);

  %let raw=%scan(&syspbuff,&i);

%end;

%else %do;

  %let i=%eval(&i+1);

  %let m=%eval(&m+1);

  %let raw=%scan(&syspbuff,&i);

%end;

%end;

%mend CPSMACRO;

%CPSMACRO(                                 <-- I run the macro and input the physical name of three raw data files, for example.

'C:\cps\cpsb95\cpsb9506'

'C:\cps\cpsb95\cpsb9507'

'C:\cps\cpsb95\cpsaug95.dat');

______________________________________________________________________

This macro works only for the first two data files, and yields an error message (ERROR: Literal contains unmatched quote) for the third one.

I've tried both single-quote and double-quote, but neither works. Would you please help me? Thank you so very much.

Rakkoo

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Without testing your code, I will guess that your problem is simply that periods are being treated as delimiter when you call the scan function. You can control what is, and isn't used as a delimiter, by specifying the modifier option.  Take a look at:

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

View solution in original post

2 REPLIES 2
art297
Opal | Level 21

Without testing your code, I will guess that your problem is simply that periods are being treated as delimiter when you call the scan function. You can control what is, and isn't used as a delimiter, by specifying the modifier option.  Take a look at:

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

Rakkoo
Fluorite | Level 6

Excellent! It was the delimiter! Now the macro works. Thanks a lot!  Smiley Happy

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 3014 views
  • 0 likes
  • 2 in conversation