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

hello,

plz tell how do i use the variable unique id to the other dataset ? 

as it shows the error that i have not referenced it .

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 data test;
74 set class.car_sales(keep= unique_id Manufacturer Model);
ERROR: The variable unique_id in the DROP, KEEP, or RENAME list has never been referenced.
75 run;
 
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TEST may be incomplete. When this step was stopped there were 0 observations and 0 variables.
WARNING: Data set WORK.TEST was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.02 seconds
 
 
76
77 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
89
 
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

The data set TEST contains UNIQUE_ID.

 

The data set CLASS.CAR_SALES does not.

 

To use TEST, it must appear on the SET statement, not the DATA statement:

 

data something_new;

set test;

* Now Unique_ID will be available;

run;

View solution in original post

6 REPLIES 6
Astounding
PROC Star

That error is saying you can't use it because it doesn't exist.  If you run this program, you will see that UNIQUE_ID does not appear on the list of variables within the data set:

 

proc contents data=class.car_sales;

run;

ballardw
Super User

There is no need to attach SAS program files. Please post code or log entries into a code box opened using the forum's {I} icon:

/*Assignment3*/
/*question 1*/
libname class '/folders/myfolders/mysas';
proc import 
datafile='/folders/myfolders/mysas/car_sales.csv'
dbms=csv  out=class.car_sales replace;

data testdata;
retain org_country;
set class.car_sales;
length org_country $10.;
select (Manufacturer);
when('BMW','Audi','Mercedes') 
org_country=('Germany');
when ('Honda','Toyota')
org_country=('Japan');
when('Cadillac','Chevrolet','Chrysler','Dodge','Ford')
org_country=('US');
when('lincoln','Jaguar','Buick')
org_country=('UK');
when ('Hyundai')
org_country=('south korea');
when('Acura','Lexus')
org_country=('Japan');
otherwise org_country=('others');
end;
run;

/*question2*/
Data test;
length unique_id $20;
Set class.car_sales;
unique_id=catt(model,manufacturer);
run;

/* question3*/
data test;
set class.car_sales(keep= unique_id Manufacturer Model);
run;

The error message is quite clear: the variable UNIQUE_ID does not exist on the data set CLASS.CAR_SALES.

You added a variable name unique_id to data set named TEST in the section labeled question 2. But you do not use that set but go back to the original data class.car_sales that did not have the variable.

 

Each time you use

data test;

<code>;

run;

 

You will completely overwrite the previous version of the data set test if there are no syntax errors. Make sure that is what you want to do.

I would suggest:

/*question2*/
Data test;
length unique_id $20;
Set class.car_sales;
unique_id=catt(model,manufacturer);
run;

/* question3*/
data test2;
set test(keep= unique_id Manufacturer Model);
run;

if you actually need two different data sets.

Or if you want a single data set with only those three variables:

/*question2*/
Data test;
   length unique_id $20;
   Set class.car_sales;
   unique_id=catt(model,manufacturer);
   keep  unique_id Manufacturer Model;
run;

 

Shrutibhatnagar
Obsidian | Level 7

please tell how do i refer the unique_id to the last dataset ??

Astounding
PROC Star

The data set TEST contains UNIQUE_ID.

 

The data set CLASS.CAR_SALES does not.

 

To use TEST, it must appear on the SET statement, not the DATA statement:

 

data something_new;

set test;

* Now Unique_ID will be available;

run;

Shrutibhatnagar
Obsidian | Level 7
ok thanks 🙂 i am just a beginner .
Astounding
PROC Star

We were all beginners at some point.  Good to see you posting your questions.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1484 views
  • 1 like
  • 3 in conversation