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

1) I'm brand new here (and to programing) so sorry if this is in the wrong place.

2) my code keeps coming up with this message: 

 

Data file MYLIB.CEREAL.DATA is in a format that is native to another host, or the file encoding does not match the session
encoding. Cross Environment Data Access will be used, which might require additional CPU resources and might reduce
performance.

However, the data works just fine in my other uses for it. 

In class I brought this up to my professor concerning a different problem set and all I had to do was capitalize some letters inbetween quotation marks, so I think this has an easy fix but for the life of me I can't figure it out. I've been messing with this for the better part of an hour and still it won't come up. I'm attaching a screenshot of what the dataset looks like (in case it's something silly like capitalization again). 

My code: 
%let mgf1 = 'K';
%let mgf2 = 'G';
%let Nutrient = Sugar;
proc ttest data=MyLib.cereal h0=0 alpha=0.05 sides=2 ;
class mgf;
where mgf in('&mgf1','&mgf2');
var &Nutrient;
title '&Nutrient affect on &mgf1 and &mgf2';
run;
title;

Screen Shot 2016-12-01 at 5.53.35 PM.png
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You have too many quotation marks. You have quotes when you use your macro variables and in your macro variable definition.

 

Drop the quotations marks from the macro variables. 

 

You also need double quotes in your WHERE clause so the macro variables resolve, otherwise they won't. And that's probably why you have no results. 

 

data cereal;
set mylib.cereal;
run;
%Let mgf1=G;
%Let mgf2=Q;
%Let Nutrient=Sodium;
title "&Nutrient affect on &mgf1. and &mgf2.";
proc ttest data=cereal h0=0 alpha=0.05 sides=2 ;
class Mgf;
where Mgf in("&mgf1","&mgf2");
var &Nutrient;
run;

View solution in original post

9 REPLIES 9
Reeza
Super User

I'm assuming you didn't create this dataset. Since someone else created it, if the created it on a different system you get this NOTE. It's not an issue and shouldn't affect your data.

 

If you want to remove it from appearing, copy your data over to work and use it from there instead.

 

 

/*Brings it into your system*/
data cereal;
set mylib.cereal;
run;

/*writes it back out as your system*/
data mylib.cereal;
set cereal;
run;

And now use cereal instead of mylib.cereal. You shouldn't see the error message anymore.

You could replace the dataset with the one you just created to remove the error entirely.

I think the quotes error is different and relates to 

 

option validvarname = Any/V7. 

 

kimmy_m66
Calcite | Level 5
I just tried that. Now I'm getting " No observations were selected from data set WORK.CEREAL."
ballardw
Super User

Please show the complete code you used to copy the dataset and what generated the message about "zero observations". May be a spelling error in the data set name one way or another

kimmy_m66
Calcite | Level 5

data cereal;
set mylib.cereal;
run;

%Let mgf1='G';
%Let mgf2='Q';
%Let Nutrient=Sodium;
title "&Nutrient affect on &mgf1 and &mgf2";
proc ttest data=cereal h0=0 alpha=0.05 sides=2 ;
class Mgf;
where Mgf in('&mgf1','&mgf2');
var &Nutrient;
run;

I'm thinking it's something to do capitalization or ; or something silly. Because it wasn't reading the observations when it was in the library either. 

Reeza
Super User

It's possible it's case sensitive, or the library declaration is case sensitive.

 

If you right click the dataset and hit properties one field should have the dataset name. Use that to refer to it. 

kimmy_m66
Calcite | Level 5

The thing is, the library worked in a different dataset. It's when I started doing %Let that it doesn't recognize the dataset

Reeza
Super User

You have too many quotation marks. You have quotes when you use your macro variables and in your macro variable definition.

 

Drop the quotations marks from the macro variables. 

 

You also need double quotes in your WHERE clause so the macro variables resolve, otherwise they won't. And that's probably why you have no results. 

 

data cereal;
set mylib.cereal;
run;
%Let mgf1=G;
%Let mgf2=Q;
%Let Nutrient=Sodium;
title "&Nutrient affect on &mgf1. and &mgf2.";
proc ttest data=cereal h0=0 alpha=0.05 sides=2 ;
class Mgf;
where Mgf in("&mgf1","&mgf2");
var &Nutrient;
run;
Kurt_Bremser
Super User

As @Reeza already mentioned, you have a problem with quotes. Macro variables are not resolved inside single quotes.

And you should not use any quotes around values when defining macro variables, unless you want the quotes to be part of the macro variable value!

The macro preprocessor only knows the data type text, so quotes are almost never needed.

 

So in your example, your where condition is looking for the values &mgf1 and &mgf2, instead of the intended K and G.

 

kimmy_m66
Calcite | Level 5

Yes thank you! This was the solution 🙂 Got it all figured out before it was due luckily

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 9 replies
  • 3911 views
  • 0 likes
  • 4 in conversation