Recently in the SAS Community Library: Your often contains the information you need, but not sequenced in the order required for processing. @SASJedi shows you how to properly sequence data so you can compare the data in one table to the data in another, conduct merges or joins and more.
Hi guys,
suppose to have the following:
data DB;
input ID :$20. Admission :date09. Discharge :date09. Index1 Index2;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2017 25JAN2017 1 1
0001 22FEB2018 03MAR2018 0 1
0001 30JAN2019 04MAR2019 0 1
0002 01DEC2018 14DEC2018 1 1
0002 25DEC2018 02JAN2019 0 1
0003 09JAN2016 25JAN2016 1 1
0003 29JAN2018 12FEB2018 0 1
0004 02FEB2014 12MAR2014 1 0
0004 02DEC2018 11SEP2019 0 1
;run;
Is there a way to get the following?
data DB1;
input ID :$20. Admission :date09. Discharge :date09. Index1 Index2;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2017 25JAN2017 1 1
0001 22FEB2018 03MAR2018 0 0
0001 30JAN2019 04MAR2019 0 0
0002 01DEC2018 14DEC2018 1 1
0002 25DEC2018 02JAN2019 0 0
0003 09JAN2016 25JAN2016 1 1
0003 29JAN2018 12FEB2018 0 0
0004 02FEB2014 12MAR2014 1 0
0004 02DEC2018 11SEP2019 0 1
;run;
In other words the column Index2 should be updated to have "1" only if "1" is present in column Index1 at the same row otherwise 0. This only if for each ID there is more than "1" in variable Index2 (i.e., "1" is repeated). For example, nothing should happen for ID 0004.
Thank you in advance
... View more
Boa tarde, tenho duas tabelas e gostaria de gerar/exportar um arquivo único, em que, cada tabela ficasse em uma aba do excel. Como fazer este procedimento?
... View more
Brand new to SAS. I'm doing something that I expect is relatively easy, but I'm struggling to get it right. The requirement is basic - I'm reading in a long file with many rows, if a record matches a criteria I want it to be shipped to a different "bypass" file that I'll work on in a later process, but it should be removed from the original read-in file. Environment is zOS - input file is defined and passed in via JCL (all working). I get the following errors if I remove my actual logic - if I leave the FILENAME statement in without referencing it there's no errors. ERROR: Invalid logical name. ERROR: Error in the FILENAME statement. ERROR: Invalid file, BYPASS_FILE. FILENAME BYPASS_FILE BYPASS1;
/***********************************************************/
/* READ FILE */
/***********************************************************/
DATA DATAIN;
INFILE DATAIN;
INPUT
@ 00001 RECORD_NUMBER $CHAR8.
@ 01769 COMPONENT_STATUS $CHAR1.
;
/*******************************************************************/
/* CREATE BYPASS FILE - USED TO STORE RECORDS WHICH HAVE AN */
/* INACTIVE COMPONENT: COMPONENT_STATUS = I */
/*******************************************************************/
IF COMPONENT_STATUS = 'I' THEN DO;
FILE BYPASS_FILE;
PUT;
DELETE;
END;
... View more
Hello SAS Users - Here is an example that is baffling me and my team mate. data test; input name1 $ name2 $; datalines; AA BB CC DD EE FF HH PP ; run; data name; input code $; datalines; AA FF HH ; run; proc sql; create table result as select * from test where name1 in (select name1 from name) ; /*name1 doesn't exist in the "name" dataset */ quit ; NOTE: Table WORK.RESULT created, with 4 rows and 2 columns. The last proc sql step should result in an error because there is no field called "name1" in dataset name but it does not give us an error. Instead it does the search, and gives us the entire "test" dataset. But if I change the last proc sql to read like below: proc sql; create table result as select * from test where name1 in (select x from name); quit; ERROR: The following columns were not found in the contributing tables: x. Shouldn't I get an error response in both cases? Or maybe there is something I don't understand about SAS in this. Thank you for any insight you can provide.
... View more
A raw data file is listed below: RANCH,1250,2,1,Sheppard Avenue,"$64,000" SPLIT,1190,1,1,Rand Street,"$65,850" CONDO,1400,2,1.5,Market Street,"80,050" TWOSTORY,1810,4,3,Garris Street,"$107,250" RANCH,1500,3,3,Kemble Avenue,"$86,650" SPLIT,1615,4,3,West Drive,"94,450" SPLIT,1305,3,1.5,Graham Avenue,"$73,650" The following SAS program is submitted using the raw data file as input: data work.condo_ranch; infile 'file-specification' dsd; input style $ @; if style = 'CONDO' or style = 'RANCH'; input sqfeet bedrooms baths street $ price : dollar10.; run; can you please help me out in this case , why only 3 observations are in output data set , ? in input there are 5 variables so there should be 5 observation
... View more