sas

SAS numeric to character conversion?

核能气质少年 提交于 2021-01-27 14:57:23
问题 When we convert a numeric to character , we should use a numeric format like the following data test ; prodID = 001 ; result = put(prodID , 1.) ; run ; proc print ; run ; I also tried to use a character format $1. , and it also worked data test ; prodID = 001 ; result = put(prodID , $1.) ; *I am using $1. here ; run ; proc print ; run ; Question is why did the second code work ? It was not supposed to work . Should we use a numeric or character format or it does not matter ? 回答1: You do get a

SAS PROC IMPORT Multiple SAV Files- Force SPSS Value Labels to Create UNIQUE SAS Format Names

放肆的年华 提交于 2021-01-07 02:52:14
问题 Sometimes if I import multiple SAV files into the SAS work library, one variable imported later on overwrites the display text (i.e., the format) of an earlier imported variable with a similar name. I've determined that this is because the later dataset's variable produces a format name for the custom format (from SPSS Values Labels) that is identical to format name from the earlier variable, even though the variables have different definitions in the Value Labels attributes in the SAV files.

SAS PROC IMPORT Multiple SAV Files- Force SPSS Value Labels to Create UNIQUE SAS Format Names

微笑、不失礼 提交于 2021-01-07 02:52:04
问题 Sometimes if I import multiple SAV files into the SAS work library, one variable imported later on overwrites the display text (i.e., the format) of an earlier imported variable with a similar name. I've determined that this is because the later dataset's variable produces a format name for the custom format (from SPSS Values Labels) that is identical to format name from the earlier variable, even though the variables have different definitions in the Value Labels attributes in the SAV files.

SAS LOOP - create columns from the records which are having a value

梦想的初衷 提交于 2021-01-04 04:24:20
问题 Suppose i have random diagnostic codes, such as 001, v58, ..., 142,.. How can I construct columns from the codes which is 1 for the records? Input: id found code 1 1 001 2 0 v58 3 1 v58 4 1 003 5 0 v58 ...... ...... 15000 0 v58 Output: id code_001 code_v58 code_003 ....... 1 1 0 0 2 0 0 0 3 0 1 0 4 1 0 0 5 0 0 0 ......... ......... 回答1: You will want to TRANSPOSE the values and name the pivoted columns according to data (value of code ) with an ID statement. Example: In real world data it is

SAS LOOP - create columns from the records which are having a value

懵懂的女人 提交于 2021-01-04 04:13:18
问题 Suppose i have random diagnostic codes, such as 001, v58, ..., 142,.. How can I construct columns from the codes which is 1 for the records? Input: id found code 1 1 001 2 0 v58 3 1 v58 4 1 003 5 0 v58 ...... ...... 15000 0 v58 Output: id code_001 code_v58 code_003 ....... 1 1 0 0 2 0 0 0 3 0 1 0 4 1 0 0 5 0 0 0 ......... ......... 回答1: You will want to TRANSPOSE the values and name the pivoted columns according to data (value of code ) with an ID statement. Example: In real world data it is

Populate SAS macro-variable using a SQL statement within another SQL statement?

柔情痞子 提交于 2021-01-01 10:25:48
问题 I stumbled upon the following code snippet in which the variable top3 has to be filled from a table have rather than from an array of numbers. %let top3 = 14 15 42; /* This should be made obsolete.. */ %let no = 3; proc sql; create table want as select * from (select x, y from foo) a %do i = 1 %to &no.; %let current = %scan(&top3.,&i.); /* What do I need to put here? */ left join (select x, y from bar where z=&current.) row_&current. on a.x = row_&current..x %end; ; quit; The table have

I want to extract month data from a datetime format column in SAS

天大地大妈咪最大 提交于 2020-12-13 02:57:06
问题 I have a data in format 01 Jan 19.00.00 (datetime), and I want to extract the month name only from it. Tried the below code but getting output in numbers i.e. 1 2 3 and so on. I want the output either in Jan Feb mar format or January February march format. data want; set detail; month = month(datepart(BEGIN_DATE_TIME)); run; 回答1: You can use the MONNAME format. data test; dt = datetime(); monname = put(datepart(dt),MONNAME.); put monname=; run; If you want "OCT" not "OCTOBER" you can add a 3

How to get current month name and year in SAS using macro

北战南征 提交于 2020-11-29 11:50:40
问题 I am triggering a mail in SAS which should holds current month and year in the mail How can I create macro variables &month &year such that &month should display October &year should display 2020 Currently using %let sysmonth= %sysfunc(month("&sysdate"d)); %let sysyear= %sysfunc(year("&sysdate"d)); %put &sysmonth &sysyear; But I am getting month in number but i want the month in words 回答1: Use PUTN with format MONNAME %put %sysfunc(PUTN("&sysdate"d, monname.)); ------ LOG ------ October 回答2:

How to get current month name and year in SAS using macro

[亡魂溺海] 提交于 2020-11-29 11:49:07
问题 I am triggering a mail in SAS which should holds current month and year in the mail How can I create macro variables &month &year such that &month should display October &year should display 2020 Currently using %let sysmonth= %sysfunc(month("&sysdate"d)); %let sysyear= %sysfunc(year("&sysdate"d)); %put &sysmonth &sysyear; But I am getting month in number but i want the month in words 回答1: Use PUTN with format MONNAME %put %sysfunc(PUTN("&sysdate"d, monname.)); ------ LOG ------ October 回答2: