I have the following code:
DATA WORK.PASS1 (DROP= G M);
RETAIN MONTH ACTION;
IF INDEXW(A,"Summary") THEN MONTH=UPCASE(SUBSTR(A,1,3));
IF G="Total Calls" THEN DELETE;
IF G="Total Appointments" THEN DELETE;
IF G="Total Contacts" THEN DELETE;
IF A=" " AND E=" " THEN DELETE;
IF SCAN(A,1)="MM" AND _N_=95 THEN ACTION="Arizona Calls";
This part of the code: IF SCAN(A,1)="MM" AND _N_=95 THEN DELETE; does not work. The new variable is created, but not the new observation.
Did you pull up the first 100 obs and look at the 95th line? Your code isn't the problem it's the incoming data:
infile cards dsd;
input a$ g$16.;
if g = 'Total Calls' then delete;
if scan(a,1) = 'MM' and _N_ = 10 then action = 'Arizona Calls';
i corrected it...ido not want to delete. I want to create a new observation under a new variable. It still did not work.
I recommend reading Step-by-Step Programming with Base SAS(R) Software. If you want an additional observation, you have to add an "output" statement.
IF SCAN(A,1)="MM" AND _N_=95 THEN do;
Some tips (without knowing the data):
Please don't write code all in upper case, and use indentation. Also, you can use in () rather than the 3 if statements, makes it a bit clearner. Finally, I wouldn't recommend using position of record in the dataset as your basis for logic. Quite a lot of things can change that, for instance, if you sort the dataset, or add records. Its a good way to introduce bugs into your code. Use data based logic.
data work.pass1 (drop= g m);
retain month action;
if indexw(a,"summary") then month=upcase(substr(a,1,3));
if g in ("total calls","total appointments","total contacts") then delete;
if a=" " and e=" " then delete;
if scan(a,1)="mm" and _n_=95 then action="arizona calls"; /* Why use a postition of the row in the dataset for your logic?? */
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.