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

I tried to import data from excel, the method1 does not work, but the method2 work, I don't know why.

(1) method1:

%let patients=002 003 004;
%let j=2;
%let shortID=%qscan(%superQ(Patients),&j.);*the patient ID of the jth patient from the Patients list;
filename wear "/data/work/sasusers/jxs004/GingerYang/ReAct/data/original data from ReAct/Actigraph New/&shortID./&shortID. scoring with sleep.xlsx";
PROC IMPORT OUT=wear&shortID. DATAFILE=wear DBMS=xlsx REPLACE; SHEET="Daily"; GETNAMES=YES;RUN;

 

(2)method2:

%let shortID=003;
filename wear "/data/work/sasusers/jxs004/GingerYang/ReAct/data/original data from ReAct/Actigraph New/&shortID./&shortID. scoring with sleep.xlsx";
PROC IMPORT OUT=wear&shortID. DATAFILE=wear DBMS=xlsx REPLACE; SHEET="Daily"; GETNAMES=YES;RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

I suspect the macro quoting is causing problems.  It *should* work fine, but sometimes that macro quoting is not automatically removed like it should be.  

 

Does this work:

 

%let patients=002 003 004;
%let j=2;
%let shortID=%scan(&Patients,&j.);

?


If it does, that would confirm it's a macro unquoting problem.  You could either avoid the macro quoting (as above) or explicitly %unquote the value with something like:

 

PROC IMPORT OUT=wear%unquote(&shortID)
BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

Are there errors in the SAS log?


Show us the log by clicking on the {i} icon and pasting the log into the window that appears. Do not provide the log any other way. Thank you.

--
Paige Miller
Reeza
Super User

Add the following options to your code, and check your log.

 

options mprint symbolgen;

Put that before your code, run it and then check your log. 

 


@JShi wrote:

I tried to import data from excel, the method1 does not work, but the method2 work, I don't know why.

(1) method1:

%let patients=002 003 004;
%let j=2;
%let shortID=%qscan(%superQ(Patients),&j.);*the patient ID of the jth patient from the Patients list;
filename wear "/data/work/sasusers/jxs004/GingerYang/ReAct/data/original data from ReAct/Actigraph New/&shortID./&shortID. scoring with sleep.xlsx";
PROC IMPORT OUT=wear&shortID. DATAFILE=wear DBMS=xlsx REPLACE; SHEET="Daily"; GETNAMES=YES;RUN;

 

(2)method2:

%let shortID=003;
filename wear "/data/work/sasusers/jxs004/GingerYang/ReAct/data/original data from ReAct/Actigraph New/&shortID./&shortID. scoring with sleep.xlsx";
PROC IMPORT OUT=wear&shortID. DATAFILE=wear DBMS=xlsx REPLACE; SHEET="Daily"; GETNAMES=YES;RUN;


 

JShi
Calcite | Level 5

the information in log:

23 options symbolgen mlogic mprint;
24 %let patients=002 003 004;
25 %let j=2;
26 %let shortID=%qscan(%superQ(Patients),&j.);*the patient ID of the jth patient from the Patients list;
SYMBOLGEN: Macro variable J resolves to 2
27 filename wear "/data/work/sasusers/jxs004/GingerYang/ReAct/data/original data from ReAct/Actigraph
27 ! New/&shortID./&shortID. scoring with sleep.xlsx";
SYMBOLGEN: Macro variable SHORTID resolves to 003
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.
SYMBOLGEN: Macro variable SHORTID resolves to 003
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.


28 PROC IMPORT OUT=wear&shortID. DATAFILE=wear DBMS=xlsx REPLACE; SHEET="Daily"; GETNAMES=YES;RUN;
SYMBOLGEN: Macro variable SHORTID resolves to 003
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

NOTE: The SAS System stopped processing this step because of errors.
NOTE: Line generated by the macro variable "SHORTID".
28 wear003
___
22
___
200
ERROR 22-322: Syntax error, expecting one of the following: ;, (, DATAFILE, DATATABLE, DBMS, DEBUG, FILE, OUT, REPLACE, TABLE,
_DEBUG_.

ERROR 200-322: The symbol is not recognized and will be ignored.

 

PaigeMiller
Diamond | Level 26

Please click on the {i} icon and paste your log into the window that appears.

--
Paige Miller
Quentin
Super User

I suspect the macro quoting is causing problems.  It *should* work fine, but sometimes that macro quoting is not automatically removed like it should be.  

 

Does this work:

 

%let patients=002 003 004;
%let j=2;
%let shortID=%scan(&Patients,&j.);

?


If it does, that would confirm it's a macro unquoting problem.  You could either avoid the macro quoting (as above) or explicitly %unquote the value with something like:

 

PROC IMPORT OUT=wear%unquote(&shortID)
BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Astounding
PROC Star

Don't quote strings unless they require quoting.

 

The solution to your problem might be as simple as replacing %QSCAN with %SCAN.  Give it a try and see if that does the trick.

ballardw
Super User

Why all the quoting in

%let shortID=%qscan(%superQ(Patients),&j.);*

You are potentially introducing artifacts that aren't needed:

%let shortid= %scan(&patients,&j.);
%put shortid=&shortid.;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 7 replies
  • 920 views
  • 2 likes
  • 6 in conversation