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

Hello, 

Please I want to create factice variables but this error message is displayed, can someone help me ?

mateckma_3-1639064676515.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You likely have only READ access to the MYDATA folder. 

 

Otherwise the code you wrote would replace the exercise1 data in that folder and anyone else using it would now have a different data set. 

 

So as @PaigeMiller suggested, try writing it to the work library instead. 

 

In general, never use this:

 

data mydata.exercice1; <- Input data set

set mydata.exercice1 ; <- output data set

 

If you make a mistake you ruin the original dataset and have to recreate it from scratch. For class work that's easy but you can't always recreate a data set.


@mateckma wrote:

Thanks for the repply, I'm using a virtual machine.

My code :

data mydata.exercice1;

set mydata.exercice1 ;

homme = 0;

if genre = 1 then homme = 1;

femme= 0;

if genre = 2 then femme = 1

homme = 0;

run;

proc freq data = mydata.exercice1;

tables genre*homme  genre* femme;

run;

Error messages : 

- User does not have appropriate authorization level for library

- Error: variable FEMME not found 

  Error: variable FOMME not found 

Can you look at it again please?


data exercice1_ans;

set mydata.exercice1 ;

homme = 0;

if genre = 1 then homme = 1;

femme= 0;

if genre = 2 then femme = 1

homme = 0;

run;

proc freq data = exercice1_ans;

tables genre*homme  genre* femme;

run;

What happens if you try this?

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

You don't have write access to library MYDATA.

 

Try this:

 

data exercicel;
    set mydata.exercicel;
... the rest of your code goes here ...

 

In the future, please show us the whole log, as text (not as a screen capture). Copy the log as text and paste it into the window that appears when you click on the </> icon. Thanks.

Insert Log Icon in SAS Communities.png

--
Paige Miller
mateckma
Fluorite | Level 6

Thanks for the repply, I'm using a virtual machine.

My code :

data mydata.exercice1;

set mydata.exercice1 ;

homme = 0;

if genre = 1 then homme = 1;

femme= 0;

if genre = 2 then femme = 1

homme = 0;

run;

proc freq data = mydata.exercice1;

tables genre*homme  genre* femme;

run;

Error messages : 

- User does not have appropriate authorization level for library

- Error: variable FEMME not found 

  Error: variable FOMME not found 

Can you look at it again please?

PaigeMiller
Diamond | Level 26

Okay, I wanted to see the log, not the code. I wanted the log pasted into the window that appears when you click on the </> icon.

 

Do not split the log. Do not show us partial logs. Show us the entire log.

 

In this case, I already explained the first error. Since you have the first error, your variable FEMME and HOMME do not get created, and so these variable cannot be used until you fix the first error.

--
Paige Miller
Reeza
Super User

You likely have only READ access to the MYDATA folder. 

 

Otherwise the code you wrote would replace the exercise1 data in that folder and anyone else using it would now have a different data set. 

 

So as @PaigeMiller suggested, try writing it to the work library instead. 

 

In general, never use this:

 

data mydata.exercice1; <- Input data set

set mydata.exercice1 ; <- output data set

 

If you make a mistake you ruin the original dataset and have to recreate it from scratch. For class work that's easy but you can't always recreate a data set.


@mateckma wrote:

Thanks for the repply, I'm using a virtual machine.

My code :

data mydata.exercice1;

set mydata.exercice1 ;

homme = 0;

if genre = 1 then homme = 1;

femme= 0;

if genre = 2 then femme = 1

homme = 0;

run;

proc freq data = mydata.exercice1;

tables genre*homme  genre* femme;

run;

Error messages : 

- User does not have appropriate authorization level for library

- Error: variable FEMME not found 

  Error: variable FOMME not found 

Can you look at it again please?


data exercice1_ans;

set mydata.exercice1 ;

homme = 0;

if genre = 1 then homme = 1;

femme= 0;

if genre = 2 then femme = 1

homme = 0;

run;

proc freq data = exercice1_ans;

tables genre*homme  genre* femme;

run;

What happens if you try this?

mateckma
Fluorite | Level 6

Thanks a lots, It runs now, 

I use a virtual machine, when I copy the log to past out of the box (every where as a text), it doesn't work so, I must type all the log, I'm sorry for that.

 

 

s_lassen
Meteorite | Level 14

You may have gotten your code to work. But I am pretty sure it does not do what is wanted. You should not have the final "homme=0" statement, because it means that the variable HOMME is always set to 0. And then the exercise of setting to 1 if GENRE=1 is wasted.

 

I can see that you are pretty new to SAS. You should learn to use the ELSE statement, I think you can get the correct output like this:

data exercice1;
  set mydata.exercice1;
  if genre=1 then homme=1;
  else homme=0;
  if genre=2 then femme=1;
  else femme=0;
run;   

Or, a bit more fast and dirty: a logical expression in SAS evaluates to 1 (true) or 0 (false). So this could also be written as

data exercice1;
  set mydata.exercice1;
  homme=genre=1;
  femme=genre=2;
run;   

 

 

 

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
  • 6 replies
  • 451 views
  • 2 likes
  • 4 in conversation