Help using Base SAS procedures

Understanding set statement error

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

Understanding set statement error

Hi. I am trying to create a new variable ('vari2) based on responses to another variable. To do this, I was going to use the set statement and keep getting the same error. Code and error are below. Any help is appreciated!

data test;

set test1;

IF vari1=. THEN vari2=.;

ELSE IF vari1=(1 OR 0) THEN vari2=1;

run;

19   data test;

20   set test1;

ERROR: File WORK.test1.DATA does not exist.


Accepted Solutions
Solution
‎03-22-2013 07:57 PM
Super User
Posts: 19,820

Re: Understanding set statement error

Posted in reply to SASstudent2013

You are correct about your data and set questions.


The following isn't valid SAS code, as @Ballardw mentioned earlier.


189  ELSE IF vari1=(1 OR 0) THEN vari2=1;


You can use the following instead:

else if vari  IN (0,1) then vari2=1;



View solution in original post


All Replies
Super User
Posts: 19,820

Re: Understanding set statement error

Posted in reply to SASstudent2013

Its saying you don't have a test1 dataset created. You may have the names backwards or another error somewhere else in your code.

data test1;

set test;

IF vari1=. THEN vari2=.;

ELSE IF vari1=(1 OR 0) THEN vari2=1;

run;

Contributor
Posts: 23

Re: Understanding set statement error

Thanks. I think there's an issue with my libname statement. I have a dataset named 'test' in the folder 'Data1' and want to first create a permanent library, then create a new variable via above code.  Do you know what I'm doing wrong with the below?

Code:

libname anaysis 'X:\Proj Mgmt FOLDER\FINAL DATASET\My Data\SAS data\Data1';

data test;

set analysis.test1;

104  libname anaysis 'X:\Proj Mgmt FOLDER\FINAL DATASET\My Data\SAS

104!  data\Data1';

NOTE: Libref ANAYSIS was successfully assigned as follows:

      Engine:        V9

      Physical Name:

X:\Proj Mgmt FOLDER\FINAL DATASET\My Data\SAS

104!  data\Data1

105  data test;

106  set analysis.test1;

ERROR: Libname ANALYSIS is not assigned.

ERROR: File WORK.analysis.test1.DATA does not exist.

Super User
Posts: 5,511

Re: Understanding set statement error

Posted in reply to SASstudent2013

You changed your spelling.  You started with ANAYSIS, then switched to ANALYSIS.

Super User
Posts: 19,820

Re: Understanding set statement error

Posted in reply to SASstudent2013

Additionally, you say the data is called test, but you refer to it as Test1

Contributor
Posts: 23

Re: Understanding set statement error

Thanks for catching that. I'm not writing the real names of these datasets because of confidentiality, so I mistyped when I wrote dummy names in the forum.

Is it correct that when using the set statement, set must be the name of the existing dataset and the data step is the name of the new set?

I updated code to reflect this and am not getting any error from the set statement. However, I am getting an error for the new variable.

Code:

data analysis2; /*create new dataset called "analysis2*/

set final322; /*from existing dataset called final322*/

IF vari1=. THEN vari2=.; /*create new variable called "vari2" that has either . or 1*/

ELSE IF vari1=(1 OR 0) THEN vari2=1;

run;

Log:

185  data analysis2;

186  set final322;

188  IF vari1=. THEN vari2=.;

                            --

                            180

189  ELSE IF vari1=(1 OR 0) THEN vari2=1;

                                        --

                                        180

ERROR 180-322: Statement is not valid or it is used out of proper order. (vari2 is underlined in the log referencing this error)

Solution
‎03-22-2013 07:57 PM
Super User
Posts: 19,820

Re: Understanding set statement error

Posted in reply to SASstudent2013

You are correct about your data and set questions.


The following isn't valid SAS code, as @Ballardw mentioned earlier.


189  ELSE IF vari1=(1 OR 0) THEN vari2=1;


You can use the following instead:

else if vari  IN (0,1) then vari2=1;



Contributor
Posts: 23

Re: Understanding set statement error

Thank you!

Super User
Posts: 11,343

Re: Understanding set statement error

Posted in reply to SASstudent2013

If vari1 ever has values other than ., 0, or 1 you may want:

ELSE If vari1 in (1,0) then vari2=1;

The vari1=(1 or 0) will always be true as it will compare the portion 1 or 0 first and since SAS treats 1 as True and 0 as False then (true or false) will always resolve to true.

If vari1 doesn't take on any other values then you only need:

Else Vari2=1;

🔒 This topic is solved and locked.

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

Discussion stats
  • 8 replies
  • 273 views
  • 3 likes
  • 4 in conversation