BookmarkSubscribeRSS Feed
Cykelops
Obsidian | Level 7

Hi,

 

Seeking for help in fixing the errors as found in this code.

 

proc sql;
create table pledge9 as select
a.*,
b.waterfall_frb_ny
from   pledge8  as a left join PledgeDataLoanLevel5 as b
on a.loan_number2 = b.loan_nb
;
quit ;
proc freq data = pledge9; tables   waterfall3 *   waterfall_frb_ny   / list missing   ;run;

Screenshot of Errors

 

sas code error.PNG

Thanks,

Cykelops

 

 

10 REPLIES 10
andreas_lds
Jade | Level 19

Please post proc contents of the datasets involved.

Cykelops
Obsidian | Level 7

hi @andreas_lds 

 

How should I do that? like this >> 

proc contents data = PledgeDataLOanLevel5; run;

 

Cykelops

andreas_lds
Jade | Level 19

Yes, and for both datasets involved. You need to check if the variables you are using exist and are of same type (the vars used in the join)

Cykelops
Obsidian | Level 7

Hi @andreas_lds 

 

I am trying to insert the proc contents pledge9 or PledgeDataLoanlevel5 but it gives me syntax error. I am not really good in this and I need your guidance on this.

sas code error.PNG

 

Please advise.

 

Kurt_Bremser
Super User

Maxim 1: Read the Documentation.

I provided a link to the documentation of the CONTENTS procedure. Use it.

 

In the future, don't post pictures of code or logs. Copy/paste the text into a window opened with these buttons:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

The one indicated is for logs and other fixed-format text (like the contents of csv files), the "little running man" right next to it for SAS code.

 

And take care to post the whole shebang. In your picture, the important line is cut off.

 

I guess that you missed to use the DATA= option of the PROC CONTENTS statement.

Cykelops
Obsidian | Level 7

Hi @Kurt_Bremser 

 

Thanks for the correction. Additional question, is this proc contents data can be inserted anywhere in the code? In my understanding, we do this in order to determine the variable use (like its source excel file).

Tom
Super User Tom
Super User

@Cykelops wrote:

Hi @Kurt_Bremser 

 

Thanks for the correction. Additional question, is this proc contents data can be inserted anywhere in the code? In my understanding, we do this in order to determine the variable use (like its source excel file).


SAS programs consists of STEPS.  You can have DATA steps and PROC steps. 

 

You can place a PROC CONTENTS step anywhere you want as long you you don't try to place it in the middle of another step in your program.  If you are using PROC IMPORT to read in an external file that you have never read before then a PROC CONTENTS step right after the PROC IMPORT step makes sense so that you can check that it is the data you were expecting.

Kurt_Bremser
Super User

You use PROC CONTENTS to determine the structure of a dataset before you write the code processing the dataset. That's what Maxim 3 means: know your data before you work with it.

 

If you want code to work repeatedly and seamlessly with newly arriving input, the data must be of consistent structure.

Since you are inflicted with the typical consequences of careless use of "simple" software (Excel is anything but in reality!), you must work hard with the source of the data to get more consistent input data. This may need to involve the application of a LART.

Kurt_Bremser
Super User

Maxim 3: Know Your Data.

Run PROC CONTENTS on the dataset(s), but a quick view by opening the dataset interactively will already show you the variable names.

Right-clicking on something (dataset or column) in the user interface will also enable you to show the properties.

ballardw
Super User

Exactly the same problem as in your other thread https://communities.sas.com/t5/New-SAS-User/Error-Variable-not-Found/m-p/942814#M42332

 

Same data set, same proc contents result, no variable named LOAN in the data set. The wording is different because Proc Sql behaves a bit differently and you could have created the variable where the reference to the alias B was used.

Example that selects a variable with one name into a new name:

 

proc sql;
   select b.loan
   from (select name as loan from sashelp.class) as b
  ;
quit;

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 10 replies
  • 1106 views
  • 2 likes
  • 5 in conversation