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

I am new to SAS University but not SAS. I was hoping for a smoother transition but it hasnt gone that way so far.  I have a long program that initially uses 3 excel files. I have always used the infile statement to infile the data as a prn file.  Then follow the infile statement with an input statement to name the variables.  Thats not working at all.

 

So I tried using the snippet tool to bring in each file as an XLSX file.  I seem to be able to bring in the data.

 

But heres the dumb part - now what?  Ideally, I would like to bring in a file and then immediately do some manipulations to create new variables.  Then bring in the next file and do the same. Then the same thing with the third file.  But after I successfully bring in a file with the snippet tool, every single one of my If-Then statements is invalid.

 

I am at a loss now and need some help. I can share all my coding if needed.  Hopefully, I have made myself somewhat clear. Thanks in advance.  Below is an example of the first import. Every If-Then statement after that has an error message.

 

DATA DAILY;

/** Import an XLSX file. **/

PROC IMPORT DATAFILE="/folders/myfolders/COVER.XLSX"
OUT=WORK.COVER
DBMS=XLSX
REPLACE;
RUN;


IF MONTH=. THEN DELETE;

SUR_TYPE='AU';

****** DEFINE TIME BLOCKS ****;

IF MONTH=3 THEN BLOCK='1_MAR';
IF MONTH=4 THEN BLOCK='2_APR';
IF MONTH=5 THEN BLOCK='3_MAY';

******* DEFINE TIME BLOCK SIZE ********;

IF MONTH=3 THEN DO; N=31; N2=9; N1=N-N2; END;
IF MONTH=4 THEN DO; N=30; N2=8; N1=N-N2; END;
IF MONTH=5 THEN DO; N=31; N2=11; N1=N-N2; END;

****** DEFINE DAY TYPES ******;


IF DAYTYPE=1 THEN DAY_TYPE='WD';
IF DAYTYPE=2 THEN DAY_TYPE='WE';


****** TIME PERIOD HOURS ARE ENTERED ON THE COVER FORM;

****** DEFINE SAMPLING PROBABILITIES *****;

IF PERIOD=1 THEN TPROB=0.3;
IF PERIOD=2 THEN TPROB=0.7;

IF SITE = 701 THEN SPROB=0.6;
IF SITE = 790 THEN SPROB=0.4;

RUN;
1 ACCEPTED SOLUTION

Accepted Solutions
MichelleHomes
Meteorite | Level 14

Great to hear! Please mark the question as solved.

 

Kind Regards,

Michelle

//Contact me to learn how Metacoda software can help keep your SAS platform secure - https://www.metacoda.com

View solution in original post

4 REPLIES 4
MichelleHomes
Meteorite | Level 14

The issues you are experiencing are not SAS University Edition related but SAS syntax related. You can't have a PROC step within a data step. This is the cause of your issue and most likely you would have had error messages relating to this.

 

Rearranging your code is the first step and then I'd look at enhancing your conditional statements.

 

Kind Regards,

Michelle

 

/** Import an XLSX file.  **/

PROC IMPORT DATAFILE="/folders/myfolders/COVER.XLSX"
		    OUT=WORK.COVER
		    DBMS=XLSX
		    REPLACE;
RUN;



DATA DAILY;

SET WORK.COVER;  * This was missing in your code and is needed for SAS to read the data you imported in the process import step above;

IF MONTH=. THEN DELETE;

SUR_TYPE='AU';

****** DEFINE TIME BLOCKS ****;

IF MONTH=3 THEN BLOCK='1_MAR';
IF MONTH=4 THEN BLOCK='2_APR';
IF MONTH=5 THEN BLOCK='3_MAY';

******* DEFINE TIME BLOCK SIZE ********;

IF MONTH=3 THEN DO;  N=31; N2=9; N1=N-N2; END;
IF MONTH=4 THEN DO;  N=30; N2=8; N1=N-N2; END;
IF MONTH=5 THEN DO;  N=31; N2=11; N1=N-N2; END;

****** DEFINE DAY TYPES ******;


IF DAYTYPE=1 THEN DAY_TYPE='WD';
IF DAYTYPE=2 THEN DAY_TYPE='WE';


****** TIME PERIOD HOURS ARE ENTERED ON THE COVER FORM;

****** DEFINE SAMPLING PROBABILITIES *****;

IF PERIOD=1 THEN TPROB=0.3;
IF PERIOD=2 THEN TPROB=0.7;

IF SITE = 701 THEN SPROB=0.6;
IF SITE = 790 THEN SPROB=0.4;

RUN;

 

//Contact me to learn how Metacoda software can help keep your SAS platform secure - https://www.metacoda.com
vicdicenzo
Obsidian | Level 7

Thanks! That helped.

MichelleHomes
Meteorite | Level 14

Great to hear! Please mark the question as solved.

 

Kind Regards,

Michelle

//Contact me to learn how Metacoda software can help keep your SAS platform secure - https://www.metacoda.com
Reeza
Super User

Your method of using 'infile' would apply to text files not Excel files.

If you convert your Excel files to PRN files it would be exactly like your previously mentioned code. 

 

What version of SAS were you working on before that makes UE so different? The only difference is how you reference files, and if you worked in a server based environment that's not even significantly different. 

 

If EG, consider using the Visual Programmer mode for a more familiar interface. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 1111 views
  • 1 like
  • 3 in conversation