BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have a set of data comprising of stock code, date and stock return. i want to find the first date of every code. i use the following:
proc sort data=p05;
by code date;
run;

data pp05;
set p05;
where FIRST.code =1;
run;

ERROR: Syntax error while parsing WHERE clause.
ERROR 180-322: Statement is not valid or it is used out of proper order.

and , where to find errow 189-322?
3 REPLIES 3
LinusH
Tourmaline | Level 20
In order to use first. syntax, you must use a BY statement in your data step: BY code;
The =1 is unnecessary, it is implied TRUE. And I don't believe you can use FIRST. together with WHERE (since WHERE does not aware of what is going on in the data step, IF is).

/Linus
Data never sleeps
deleted_user
Not applicable
tried the following:

proc sort data=p05;
by code ;
run;

data pp05;
set p05;
if FIRST.code ;
run;

but still doesn't work. so i guess maybe something is wrong with my SAS. i am going to school to use another computer to try
anyway, thank
SushilNayak
Obsidian | Level 7
Hey tzsmile,
you forgot to put the by variable in the datastep...

proc sort data=p05;
by code ;
run;

data pp05;
set p05;
by code ;
if FIRST.code ;
run;

just add "by code ;" in the datastep like i have done in the above code and you'll see your code without any errors/ warnings.

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

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1952 views
  • 0 likes
  • 3 in conversation