SAS commands for Windows to Linux

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

SAS commands for Windows to Linux

Hi,

I need to use interactive SAS of Linux.

I already have a code which works really well in Windows and try to convert it for Linux.

I am trying to find any help guide for SAS Linux, but it is hard to find one.

Can anyone help with this?

My code is..

libname list "D:\list\";

libname sasdata "D:\sasdata\";

data list.a1;

keep fname;

rc=filename("mydir","C:\Users\owner\Desktop\upc");

did=dopen("mydir");

nf = dnum(did);

do i=1 to nf;

fname=dread(did, i);

output;

end;

rc=dclose(did);

run;

data _null_; set list.a1; call symput('n', trim(left(_n_))); run;

%macro aa;

%do i=2 %to 2;

data _null_;

set list.a1; if _n_=&i;

call symput('f', '"C:\Users\owner\Desktop\upc\'||trim(fname)||'"');

run;

%end;

%mend aa;

%mend;

I guess that the first part, which generates the list of all the file in my directory does not work well.

I already changes the path for Linux properly(e.g., /home/usr17/jhhuh ...). I guess that dnum, dopen, dread, dclose do not work well in Linux.

Any suggestion or advice will be appreciated!


Accepted Solutions
Solution
‎03-06-2013 01:54 PM
PROC Star
Posts: 1,167

Re: SAS commands for Windows to Linux

You should just use

rc=filename("mydir","/h2/usr17/jhhuh/prod/mayo");

instead of

rc=filename("mydir","ls /h2/usr17/jhhuh/prod/mayo");

the "ls " at the start is asking to run the Unix ls command, to return the files in a directory, like the Windows dir command.

Tom

View solution in original post


All Replies
Super Contributor
Posts: 644

Re: SAS commands for Windows to Linux

Can you post the Unix version of the code?  Preferably from the log showing all the error messages.

Richard

Contributor
Posts: 20

Re: SAS commands for Windows to Linux

Posted in reply to RichardinOz

I changed the path and tried to use the code below.

libname list "/h2/usr17/jhhuh/data/list";

libname sasdata "/h2/usr17/jhhuh/data/sasdata/prod";

data a1;

keep fname;

rc=filename("mydir","ls /h2/usr17/jhhuh/prod/mayo");

did=dopen("mydir");

nf = dnum(did);

do i=1 to nf;

fname=dread(did, i);

output;

end;

rc=dclose(did);

run;

data _null_; set list.a1; call symput('n', trim(left(_n_))); run;

%macro infile;

%do i=3 %to 4;

data _null_;

set a1; if _n_=&i;

call symput('f', '"/h2/usr17/jhhuh/prod/mayo/'||trim(fname)||'"');

run;

data sasdata.storeinfo&i; infile &f firstobs=2;

input  OU$ EST_ACV$ Market_Name$ 20-44 Open Clsd MskdName$ ;

run;

%end;

%mend infile;

%infile;

I got a Note message at the first part.

The message says...

NOTE: Argument 1 to function DNUM at lint 9 column 6 is invalid.

ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY expression is missing, zero, or invalid.

NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values.

Each Places is given by: (Number of times) at (Line)Smiley SadColumn).

1 at 9:6

NOTE: The SAS System stopped processing this step because of errors.

I guess that it couldn't read

'nf=dnum(did);

part.

I want to use this code for reading in multiple data in a directory.

So the first step is list all file in the directory.

I am perplexed because this is first time for me to use SAS in Linux.

PROC Star
Posts: 1,167

Re: SAS commands for Windows to Linux

UNIX directories have a different structure, without a drive letter, and using forward slashes. So for example you would need to specify something like:

/Users/owner/Desktop/upc

Also they are case sensitive. I think if you convert your directories to the correct ones for your Linux environment, this should work.

Tom

Contributor
Posts: 20

Re: SAS commands for Windows to Linux

I changed it but it did not work well.

So.. you think that I need to check my path of directory?

I checked my directory, but it has no problem.

Is there any other cause of the error?

Super User
Super User
Posts: 7,039

Re: SAS commands for Windows to Linux

If the argument to the DNUM function is invalid then that means the DOPEN function did not work.

Check the value of DID variable before trying to use it with DNUM().

Contributor
Posts: 20

Re: SAS commands for Windows to Linux

You were right. the value of DID in Windows is 1, but it is 0 in Linux.

I wrote the path as ls h2/hsr/.....

I had to use /h2/usr/....

Thank you so much!

Solution
‎03-06-2013 01:54 PM
PROC Star
Posts: 1,167

Re: SAS commands for Windows to Linux

You should just use

rc=filename("mydir","/h2/usr17/jhhuh/prod/mayo");

instead of

rc=filename("mydir","ls /h2/usr17/jhhuh/prod/mayo");

the "ls " at the start is asking to run the Unix ls command, to return the files in a directory, like the Windows dir command.

Tom

Contributor
Posts: 20

Re: SAS commands for Windows to Linux

Thanks! I just figured out! It works beautifully!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 447 views
  • 6 likes
  • 4 in conversation