
11 hours ago
ChrisNZ
Tourmaline | Level 20
Member since
06-23-2011
- 6,978 Posts
- 1,868 Likes Given
- 649 Solutions
- 2,748 Likes Received
-
Latest posts by ChrisNZ
Subject Views Posted 550 Friday 138 Friday 299 Friday 222 Friday 308 a week ago 341 a week ago 518 a week ago 527 a week ago 739 2 weeks ago 412 2 weeks ago -
Activity Feed for ChrisNZ
- Got a Like for Re: Changing textsize for specific values in proc sgplot SG Annotation Function. Monday
- Got a Like for Re: Financial Management Studio doesn't show any data anymore and error message is thrown out. Monday
- Got a Like for Re: Changing textsize for specific values in proc sgplot SG Annotation Function. Saturday
- Got a Like for Re: Image in title statement not inserting in PDF after password protection (ODS PDF). Friday
- Posted Re: check non ascii characters on SAS Programming. Friday
- Liked Re: check non ascii characters for Ksharp. Friday
- Posted Re: Changing textsize for specific values in proc sgplot SG Annotation Function on SAS Programming. Friday
- Posted Re: Image in title statement not inserting in PDF after password protection (ODS PDF) on SAS Programming. Friday
- Posted Re: VS Code for SAS 9.4 Extension on SAS Studio. Friday
- Posted Re: Financial Management Studio doesn't show any data anymore and error message is thrown out on Developers. a week ago
- Posted Re: Financial Management Studio doesn't show any data anymore and error message is thrown out on Developers. a week ago
- Got a Like for Re: Finding observation difference in two separate datasets. a week ago
- Posted Re: Finding observation difference in two separate datasets on SAS Programming. a week ago
- Posted Re: Finding observation difference in two separate datasets on SAS Programming. a week ago
- Posted Re: PROC FCMP w.d. format issue on SAS Procedures. 2 weeks ago
- Got a Like for Re: Writing data to from SAS to BigQuery very slow. 2 weeks ago
- Got a Like for Re: Writing data to from SAS to BigQuery very slow. 2 weeks ago
- Posted Re: Writing data to from SAS to BigQuery very slow on SAS Procedures. 2 weeks ago
- Liked Re: Writing data to from SAS to BigQuery very slow for SASKiwi. 2 weeks ago
- Liked Re: Preserve a date format in Proc Report export to Excel for Ksharp. 4 weeks ago
-
Posts I Liked
Subject Likes Author Latest Post 1 2 2 2 1 -
My Liked Posts
Subject Likes Posted 1 a week ago 3 Friday 1 Friday 2 a week ago 3 2 weeks ago -
My Library Contributions
Subject Likes Author Latest Post 2 1 3 14 3
Friday
What @Ksharp describes is the easiest way.
No need to use a convoluted logic that's hard to maintain.
One line of code does the job.
Use prxchange() instead of prxmatch() if you want to retain a list of the non-ASCII characters.
... View more
Friday
3 Likes
The attribute textsize is available for data set sganno= but not for data set dattrmap= .
See
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/p1d3djir0t86nxn1l10ig8b2jbnl.htm
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatproc/n18szqcwir8q2nn10od9hhdh2ksj.htm
So you need to overwrite the axis labels using the SG Annotation Function if you really want a different font size. That's done with something like
data ANNO;
DRAWSPACE='datavalue'; X1=0.25; Y1=3; FUNCTION='text'; TEXTSIZE=9; LABEL='Study 3'; output;
run;
Set the axis labels to colour white.
... View more
a week ago
1 Like
Your SAS system administrator should be able to contact them. Otherwise, email s u p p o r t a t s a s d o t c o m.
... View more
a week ago
If you want to use the observation order and don't care about duplicates, here is another way to flag non-common observations:
proc sort data=A out=ASORTED;
by _ALL_;
run;
proc sort data=B out=BSORTED;
by _ALL_;
run;
data WANT;
merge ASORTED(in=A)
BSORTED(in=B);
by _ALL_;
if A & ^B then src='In A only';
else if ^A & B then src='In B only';
else delete;
run;
... View more
a week ago
2 Likes
I know the total excluded is 5,000 from simple math but I'm a bit stuck on how we can do this in a SAS code.
You don't know that. Maybe there are duplicates, or unique observations in both data sets.
Never make assumptions about your data quality, and always check for all possible defects.
Assuming you won't rely on the observation order, here is one way:
data A;
X=1; output;
X=1; output;
X=2; output;
X=2; output;
run;
data B;
X=2; output;
X=3; output;
run;
proc sql;
create table WANT as
select 'In A only' as SRC, *
from (select * from A
except all
select * from B )
union all
select 'In B only' as SRC, *
from (select * from B
except all
select * from A );
quit;
This results in:
SRC
X
In A only
1
In A only
1
In A only
2 *
In B only
3
* The all keyword in except does not suppress duplicate rows, hence why the second X=2 observation is flagged by the code above.
Same thing for keeping both X=1 observations, thanks to union all .
See https://documentation.sas.com/doc/en/sqlproc/3.2/n0vo2lglyrnexwn14emi8m0jqvrj.htm
Depending on what you want, you could also use a variation of
proc sql;
create table WANT as
select *
from A
union all
select *
from B
except
(select * from A
intersect
select * from B );
quit;
... View more
2 weeks ago
This is never true?
IF lx>len THEN PUT "WARN&ING: LENGTH value too small to correctly print value"; /* Get length of integer part of value to check against planned len, issue warn if too great */
sig=3 lx=8 len=9
a=123456789012.34
b=1.23E11
... View more
01-31-2025
09:03 PM
3 Likes
Have you seen this page?
https://communities.sas.com/t5/ODS-and-Base-Reporting/Get-SUBJECT-id-to-show-on-each-page-of-a-listing-when-a-subjects/td-p/921637
You need to use the TAGSETS.RTF destination rather than RTF, and the SPANROWS option in PROC REPORT.
These almost-but-not-quite-redundant ODS destinations are anything but clear tbh.
... View more
01-30-2025
05:23 PM
1 Like
The input function only reads what it needs.
data EXAMPLE;
STR = '31.12.1970 00:00:00';
DATE = input(STRING, ddmmyy10.);
putlog DATE= date9.;
run;
DATE=31DEC1970
... View more
01-29-2025
07:14 AM
4 Likes
The value of a variable is only reset to missing in the data step's PDV at the start of a data step if
- it is not a data set variable, and
- it is not a retained variable (RETAIN statement or increment syntax).
The value of a data set variable is refreshed in the PDV when a value is read from the data set.
When none of these condition are true (data set variable, but no value read for the data set), the value in the PDV remains unchanged.
People who don't know that have not been trained properly. Not blaming them, it's very common unfortunately.
The PDV logic also explains why a Cartesian product does not take place when merging data sets in a data step.
I'll take the opportunity to complain again that the message
NOTE: MERGE statement has more than one data set with repeats of BY values.
should never have been a note, and should now be customisable to a WARNING or an ERROR, with an option similar to these:
DKRICOND=ERROR Specifies the error level to report when a variable is missing from an input data set during the processing of a
DROP=, KEEP=, or RENAME= data set option.
DKROCOND=WARN Specifies the error level to report when a variable is missing from an output data set during the processing of
a DROP=, KEEP=, or RENAME= data set option.
... View more
01-29-2025
06:30 AM
4 Likes
Use a slash to change a password.
data T1(pw=R);
A=1;
run;
proc datasets nolist ;
modify T1(write=R/W alter=R/A read=R/RR);
run;
quit;
proc print data=T1(read=RR);
run;
... View more
01-26-2025
02:02 AM
1 Like
@webart999ARM
Here's my take.
A more descriptive macro name , much less code (easier to understand and maintain) and more checks (input vetting, data set contains variables).
I don't care about unique temp dataset name or global macro variable as they are short-lived and not useful to me.
Macro:
/* Macro used in a SQL select statement that returns the variable names from a data set. */
/* If column &varname doesn't exist, it's added to the list with a missing numeric value (dot). */
/* If column &varname already exists in the data set, simply list the variable names. */
%macro varaddsql(data=_LAST_, varname=, alias=);
%*** INIT ***;
%local rc dsvars addalias addvar;
%let data = %upcase(%sysfunc(compress(%superq(data ),.,kn))); %* clean input ;
%let varname= %upcase(%sysfunc(compress(%superq(varname), ,kn))); %* clean input ;
%let alias = %upcase(%sysfunc(compress(%superq(alias ), ,kn))); %* clean input ;
%if ^%sysfunc(exist(&data)) %then %do; %* vet input ;
%put ERROR: Dataset &data does not exist. Macro VARADDSQL will stop executing. ;
%return;
%end;
%*** MAIN ***;
%if &data = _LAST_ %then %let data = &syslast. ; %* fetch _last_ data set name ;
%if %length(&alias.) %then %let addalias = "&alias.." || ; %* prep table alias to add to variable name ;
%let rc = %sysfunc(dosubl(%nrstr( ;
proc contents data=&data noprint out=ZZ_VARADDSQL(keep=NAME); %* get variable names ;
run;
proc sql noprint;
select &addalias. upcase(NAME)
into :dsvars separated by ',' from ZZ_VARADDSQL; %* create variable list ;
drop table ZZ_VARADDSQL; %* drop temp table ;
quit;
)));
%if ^%length(&dsvars.) %then %do; %* check var list ;
%put ERROR: Dataset &data contains no variables. Macro VARADDSQL will stop executing. ;
%return;
%end;
%if ^%sysfunc(findw( %quote(&dsvars), &varname, %str(,.) ))
%then %let addvar= , . as &varname.; %* prep missing variable to add to var list ;
%*** RETURN COMMA-DELIMITED LIST OF VARIABLES, INCLUDING MISSING VARIABLE IF NEEDED ***;
&dsvars. &addvar.
%mend varaddsql;
Unit Test:
/*****************************************************************************
Unit test for program varaddsql.sas
******************************************************************************
Who When What
******************************************************************************
---
******************************************************************************/
%*************************************************************************;
%*** FAILURE expected ****************************************************;
%*************************************************************************;
* Invalid dataset name = > Message is displayed and error triggered.;
proc sql;
create table WANT as
select %varaddsql(data=SASHELP.CLASSX, varname=HEIGHT)
from SASHELP.CLASS;
quit;
* No variables in data set = > Message is displayed and error triggered.;
data BAD;
run;
proc sql;
create table WANT as
select %varaddsql(data=BAD, varname=HEIGHT)
from BAD;
quit;
%*************************************************************************;
%*** SUCCESS expected ****************************************************;
%*************************************************************************;
* Variable exists = > List of variables returned.;
proc sql;
create table WANT1 as
select %varaddsql(data=SASHELP.CLASS, varname=HEIGHT)
from SASHELP.CLASS;
quit;
* Variable exists, data set name stripped of invalid characters = > List of variables returned.;
proc sql;
create table WANT1 as
select %varaddsql(data=SASHELP.CLASS@, varname=HEIGHT)
from SASHELP.CLASS;
quit;
* Variable exists and _LAST_ data set used = > List of variables returned.;
proc sql;
create table WANT2 as
select %varaddsql(data=_LAST_, varname=HEIGHT)
from SASHELP.CLASS;
quit;
* Variable does not exist = > List of variables returned with added variable.;
proc sql;
create table WANT3 as
select %varaddsql(data=SASHELP.CLASS, varname=BLOODPRESSURE)
from SASHELP.CLASS;
quit;
* Variable does not exist and alias used = > List of variables returned with alias and with added variable.;
data IQ;
NAME='Jane '; IQ=150; output;
NAME='Janet'; IQ=144; output;
run;
proc sql;
create table WANT4 as
select %varaddsql(data=SASHELP.CLASS, varname=BLOODPRESSURE, alias=a)
,b.IQ
from SASHELP.CLASS as a
left join
IQ as b
on a.NAME=b.NAME;
quit;
... View more