Hi,
I have the following code:
DATA WORK.PASS1 (DROP= G M);
SET WORK.TELEMKT;
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";
RUN;
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.
1) You don't have 'THEN DELETE' in the code, only in your question does it say delete.
2) You should pull up the first 100 obs, look at what line 95 has, if it doesn't match your if statement you won't get '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.
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:
data have;
infile cards dsd;
input a$ g$16.;
cards;
MM,Total Calls
MM,Total Calls
MM,Total Calls
MM,Total Calls
MM,Total Calls
MM,Total Calls
MM,Total Calls
MM,Total Calls
MM,Total Calls
MM,
;
DATA WANT;
set have;
if g = 'Total Calls' then delete;
if scan(a,1) = 'MM' and _N_ = 10 then action = 'Arizona Calls';
run;
it works
gobejo wrote:
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.
data work.pass1;
...
output;
IF SCAN(A,1)="MM" AND _N_=95 THEN do;
ACTION="Arizona Calls";
output;
end;
run;
Hi,
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);
set work.telemkt;
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?? */
run;
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!
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.