Quit SAS without really quitting

when a SAS syntax generates errors involving macro's, SAS stops doing anything even if you submit a new command.  You can submit the following to clean-quit without shutting down SAS.

;*%mend;*);*';*";**/;

Adding a note to SAS results

data NOTES;

input  Notes & $ 1-100;

datalines;

This is my note

;

run;

 

proc print;

run;

 

*****************

data _null_;
set n_level_info;
call symput ("NLevels", NLevels);
run;

data NOTES;
input Notes $ 1-100;
textResolved=dequote(resolve(quote(Notes)));
datalines;
This is the way I add a note in a data step.
This is an example of how I can use a macro --> &NLevels .

;
run;

data notes2;
set notes;
keep textResolved;

run;

Data editing in SAS

My data looks like this:

VAR1
TITLE A
APPLICATION #1
APPLICATION #2
APPLICATION #3
TITLE B
APPLICATION #4
APPLICATION #5
APPLICATION #6
TITLE C
APPLICATION #4
APPLICATION #5
APPLICATION #6

I’d like the result to look like VAR2 below

VAR1 VAR2
TITLE A TITLE A
APPLICATION #1 TITLE A
APPLICATION #2 TITLE A
APPLICATION #3 TITLE A
TITLE B TITLE B
APPLICATION #4 TITLE B
APPLICATION #5 TITLE B
APPLICATION #6 TITLE B
TITLE C TITLE C
APPLICATION #4 TITLE C
APPLICATION #5 TITLE C
APPLICATION #6 TITLE C

To be more exact, I’d like it to be like this, but if I get above, I can get this myself:

VAR1 VAR2
APPLICATION #1 TITLE A
APPLICATION #2 TITLE A
APPLICATION #3 TITLE A
APPLICATION #4 TITLE B
APPLICATION #5 TITLE B
APPLICATION #6 TITLE B
APPLICATION #4 TITLE C
APPLICATION #5 TITLE C
APPLICATION #6 TITLE C

Thanks Charly:

*****;
data a;
input VAR1 &$30.;
cards;
TITLE A
APPLICATION #1
APPLICATION #2
APPLICATION #3
TITLE B
APPLICATION #4
APPLICATION #5
APPLICATION #6
TITLE C
APPLICATION #4
APPLICATION #5
APPLICATION #6
;

data b;
set a;
if var1 =: 'TITLE' then var2=var1;
else output;
retain var2;
run;

proc print ; run;

Creating a series of dummy variables

Thanks Russ:

Based on the lowest and highest grade, the following creates a series of dummy variables indicating which grade level is served --- by schools.

data one;
input ID LOWEST_GRADE HIGHEST_GRADE;
cards;
1 4 9
2 9 12
;

data new;
array grades(*) grade1-grade12;
set one;
do i =1 to dim(grades);
if i ge lowest_grade and i le highest_grade then grades(i)=1;
else grades(i)=0;
end;
run;

proc print;
run;

SAS Drop variables when all values are missing

/*http://ftp.sas.com/techsup/download/sample/datastep/dropvar.html*/
%let abc=&syslast;
data _null_;
set &abc end=end;
array test (*) _numeric_;
* array allmiss (8) $ (8*'true');
array allmiss (3000) $ (3000*'true');

length list $ 5000;

do i=1 to dim(test);
if test(i) ne . then allmiss(i)='false';
end;
if end=1 then
do i= 1 to dim(test);
if allmiss(i) ='true' then list=trim(list)||' '||trim(vname(test(i)));
end;
call symput('mlist',list);
run;

data &abc ;
set &abc ;
drop &mlist;
run;

SAS Converting string values into numeric values

proc contents data=xxx1 position;
ods output position=kuekawa1;
run;

data kuekawa2;
set kuekawa1;
if type="Char" then do;
x1=compress(variable||"_n=input(");
x2=x1||variable||",7.);";
syntax=compress(x2);
*&var1._n=input(&var1,7.);
end;
if syntax ne "";
keep syntax;
run;

data _null_;set kuekawa2;
blank=' ';
file "C:\temp\proc_contents1.txt";
put
(syntax) (100.0);
run;

data xxx2;
set xxx1;
%include "C:\temp\proc_contents1.txt";
run;

SAS Read from the Web

filename foo url "http://www.cnn.com";
data jaz;
infile foo length=len /*lrecl=32767*/;
input record $varying1000. len ;
put record $varying1000. len ;
if _n_=10 then stop;
run;

SAS PROC IMPORT

PROC IMPORT OUT= WORK.list
DATAFILE= ".....xlsx"
DBMS=EXCEL REPLACE;
RANGE="Sheet1$";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;