Write and run SAS programs in your web browser

Infile and snippet issues - SAS University

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Infile and snippet issues - SAS University

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;

Accepted Solutions
Solution
‎12-18-2016 01:39 PM
Super User
Posts: 1,208

Re: Infile and snippet issues - SAS University

Great to hear! Please mark the question as solved.

 

Kind Regards,

Michelle

View solution in original post


All Replies
Super User
Posts: 1,208

Re: Infile and snippet issues - SAS University

[ Edited ]

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;

 

Occasional Contributor
Posts: 10

Re: Infile and snippet issues - SAS University

Thanks! That helped.

Solution
‎12-18-2016 01:39 PM
Super User
Posts: 1,208

Re: Infile and snippet issues - SAS University

Great to hear! Please mark the question as solved.

 

Kind Regards,

Michelle

Grand Advisor
Posts: 16,367

Re: Infile and snippet issues - SAS University

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. 

Post a Question
Discussion Stats
  • 4 replies
  • 155 views
  • 1 like
  • 3 in conversation