@Curious4 wrote:
I don;t know what "write the data step to read it instead" means
You're jumping to step three. What happened with the first two steps?
Okay, The dataset exists but the data doesn't print out as expected so exports don't work
data stress2;
file '/folders/myfolders/DATASETS/DAT/dat_raw/stress2.txt';
put name 1-20 resthr 22-24 maxhr 26-28 rechr 30-32 timemin 34-36 timesec 38-40
tolerance 42;
proc print; run;
@Curious4 wrote:
Okay, The dataset exists but the data doesn't print out as expected so exports don't work
data stress2;
file '/folders/myfolders/DATASETS/DAT/dat_raw/stress2.txt';
put name 1-20 resthr 22-24 maxhr 26-28 rechr 30-32 timemin 34-36 timesec 38-40
tolerance 42;
proc print; run;
So what do you "expect"?
Then do not overwrite it by running an empty data step.
Show the complete log of your code, starting with the import. Post the log by copy/pasting it into a code box opened with </>.
data sales2018; /* there is 2 record*/ infile '/folders/myfolders/DATASETS/sales2018.txt' dlm='09'x; input month 1-2 day 4-5 year 7-10 item $ 12-17 price 19-22 sale_item $ 24-26 coupon $ 28-30 manager_log $ 32-34; proc contents; proc print; run; filename fileref '/folders/myfolders/DATASETS/sales2018.txt'; data sales2018_2; infile fileref; input month 1-2 day 4-5 year 7-10 item $ 12-20 price $ 22-27 sale_item $ 29-30 coupon $ 32-35 manager_log $ 37-40; proc print; run; filename fileref '/folders/myfolders/DATASETS/sales2019.txt'; data sales2019_2; infile fileref; input month 1-2 day 4-5 year 7-10 item $ 12-20 price $ 22-27 sale_item $ 29-30 coupon $ 32-35 manager_log $ 37-40; proc print; run; filename fileref '/folders/myfolders/DATASETS/sales2020.txt'; data sales2020_2; infile fileref; input month 1-2 day 4-5 year 7-10 item $ 12-20 price $ 22-27 sale_item $ 29-30 coupon $ 32-35 manager_log $ 37-40; proc print; run; data new; set sales2018_2 sales2019_2 sales2020_2; proc print; data stress2; file '/folders/myfolders/DATASETS/DAT/dat_raw/stress2.txt'; put name $ 1-20 resthr 22-24 maxhr 26-28 rechr 30-32 timemin 34-36 timesec 38-40 tolerance 42; proc print; run; proc contents data=stress2; run; -------------- log ------------ 1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 72 73 data sales2018; 74 75 /* there is 2 record*/ 76 infile '/folders/myfolders/DATASETS/sales2018.txt' dlm='09'x; 77 input month 1-2 day 4-5 year 7-10 item $ 12-17 price 19-22 sale_item $ 24-26 coupon $ 28-30 78 manager_log $ 32-34; 79 NOTE: The infile '/folders/myfolders/DATASETS/sales2018.txt' is: Filename=/folders/myfolders/DATASETS/sales2018.txt, Owner Name=root,Group Name=vboxsf, Access Permission=-rwxrwx---, Last Modified=07Oct2020:16:00:44, File Size (bytes)=76 NOTE: 3 records were read from the infile '/folders/myfolders/DATASETS/sales2018.txt'. The minimum record length was 1. The maximum record length was 35. NOTE: SAS went to a new line when INPUT statement reached past the end of a line. NOTE: The data set WORK.SALES2018 has 2 observations and 8 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds 79 ! proc contents; 80 NOTE: PROCEDURE CONTENTS used (Total process time): real time 0.18 seconds cpu time 0.18 seconds 80 ! proc print; 81 run; NOTE: There were 2 observations read from the data set WORK.SALES2018. NOTE: PROCEDURE PRINT used (Total process time): real time 0.04 seconds cpu time 0.04 seconds 82 83 filename fileref '/folders/myfolders/DATASETS/sales2018.txt'; 84 data sales2018_2; 85 infile fileref; 86 input month 1-2 day 4-5 year 7-10 item $ 12-20 price $ 22-27 sale_item $ 29-30 coupon $ 32-35 87 manager_log $ 37-40; 88 NOTE: The infile FILEREF is: Filename=/folders/myfolders/DATASETS/sales2018.txt, Owner Name=root,Group Name=vboxsf, Access Permission=-rwxrwx---, Last Modified=07Oct2020:16:00:44, File Size (bytes)=76 NOTE: 3 records were read from the infile FILEREF. The minimum record length was 1. The maximum record length was 35. NOTE: SAS went to a new line when INPUT statement reached past the end of a line. NOTE: The data set WORK.SALES2018_2 has 1 observations and 8 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 88 ! proc print; 89 run; NOTE: There were 1 observations read from the data set WORK.SALES2018_2. NOTE: PROCEDURE PRINT used (Total process time): real time 0.03 seconds cpu time 0.04 seconds 90 91 filename fileref '/folders/myfolders/DATASETS/sales2019.txt'; 92 data sales2019_2; 93 infile fileref; 94 input month 1-2 day 4-5 year 7-10 item $ 12-20 price $ 22-27 sale_item $ 29-30 coupon $ 32-35 95 manager_log $ 37-40; 96 NOTE: The infile FILEREF is: Filename=/folders/myfolders/DATASETS/sales2019.txt, Owner Name=root,Group Name=vboxsf, Access Permission=-rwxrwx---, Last Modified=08Oct2020:00:13:32, File Size (bytes)=76 NOTE: 3 records were read from the infile FILEREF. The minimum record length was 1. The maximum record length was 35. NOTE: SAS went to a new line when INPUT statement reached past the end of a line. NOTE: The data set WORK.SALES2019_2 has 1 observations and 8 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 96 ! proc print; 97 run; NOTE: There were 1 observations read from the data set WORK.SALES2019_2. NOTE: PROCEDURE PRINT used (Total process time): real time 0.03 seconds cpu time 0.03 seconds 98 99 filename fileref '/folders/myfolders/DATASETS/sales2020.txt'; 100 data sales2020_2; 101 infile fileref; 102 input month 1-2 day 4-5 year 7-10 item $ 12-20 price $ 22-27 sale_item $ 29-30 coupon $ 32-35 103 manager_log $ 37-40; 104 NOTE: The infile FILEREF is: Filename=/folders/myfolders/DATASETS/sales2020.txt, Owner Name=root,Group Name=vboxsf, Access Permission=-rwxrwx---, Last Modified=08Oct2020:00:13:39, File Size (bytes)=127 NOTE: 3 records were read from the infile FILEREF. The minimum record length was 40. The maximum record length was 41. NOTE: The data set WORK.SALES2020_2 has 3 observations and 8 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 104 ! proc print; 105 run; NOTE: There were 3 observations read from the data set WORK.SALES2020_2. NOTE: PROCEDURE PRINT used (Total process time): real time 0.03 seconds cpu time 0.04 seconds 106 107 108 data new; set sales2018_2 sales2019_2 sales2020_2; NOTE: There were 1 observations read from the data set WORK.SALES2018_2. NOTE: There were 1 observations read from the data set WORK.SALES2019_2. NOTE: There were 3 observations read from the data set WORK.SALES2020_2. NOTE: The data set WORK.NEW has 5 observations and 8 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.02 seconds 109 proc print; 110 111 112 113 114 NOTE: There were 5 observations read from the data set WORK.NEW. NOTE: PROCEDURE PRINT used (Total process time): real time 0.05 seconds cpu time 0.05 seconds 115 data stress2; 116 file '/folders/myfolders/DATASETS/DAT/dat_raw/stress2.txt'; 117 put name $ 1-20 resthr 22-24 maxhr 26-28 rechr 30-32 timemin 34-36 timesec 38-40 118 tolerance 42; 119 NOTE: Variable name is uninitialized. NOTE: Variable resthr is uninitialized. NOTE: Variable maxhr is uninitialized. NOTE: Variable rechr is uninitialized. NOTE: Variable timemin is uninitialized. NOTE: Variable timesec is uninitialized. NOTE: Variable tolerance is uninitialized. NOTE: The file '/folders/myfolders/DATASETS/DAT/dat_raw/stress2.txt' is: Filename=/folders/myfolders/DATASETS/DAT/dat_raw/stress2.txt, Owner Name=root,Group Name=vboxsf, Access Permission=-rwxrwx---, Last Modified=08Oct2020:16:20:11 NOTE: 1 record was written to the file '/folders/myfolders/DATASETS/DAT/dat_raw/stress2.txt'. The minimum record length was 42. The maximum record length was 42. NOTE: The data set WORK.STRESS2 has 1 observations and 7 variables. NOTE: DATA statement used (Total process time): real time 0.02 seconds cpu time 0.01 seconds 119 ! proc print; run; NOTE: There were 1 observations read from the data set WORK.STRESS2. NOTE: PROCEDURE PRINT used (Total process time): real time 0.02 seconds cpu time 0.02 seconds 120 121 proc contents data=stress2; 122 run; NOTE: PROCEDURE CONTENTS used (Total process time): real time 0.15 seconds cpu time 0.15 seconds 123 124 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 136
This step makes no sense. It will create dataset STRESS2 with one observation with all missing values for the 7 numeric variables. It will also create an empty text file. Both will replace anything that previously existed.
data stress2;
file '/folders/myfolders/DATASETS/DAT/dat_raw/stress2.txt';
put name $ 1-20 resthr 22-24 maxhr 26-28 rechr 30-32 timemin 34-36 timesec 38-40
tolerance 42;
run;
Explain in words what you want to do here.
PS Format you code to make it human readable. SAS will keep intending lines. You need to manually fix the indentation.
data sales2018;
infile '/folders/myfolders/DATASETS/sales2018.txt' dlm='09'x;
input month 1-2 day 4-5 year 7-10 item $ 12-17 price 19-22
sale_item $ 24-26 coupon $ 28-30 manager_log $ 32-34
;
run;
proc contents;
run;
proc print;
run;
With this step
115 data stress2; 116 file '/folders/myfolders/DATASETS/DAT/dat_raw/stress2.txt'; 117 put name $ 1-20 resthr 22-24 maxhr 26-28 rechr 30-32 timemin 34-36 timesec 38-40 118 tolerance 42;
you created the dataset WORK.STRESS2, but since you did not read anything, it will be empty. Since you also wrote a file (by using a FILE and a PUT statement instead of an INFILE and INPUT), this file was overwritten with one line of missing values.
You need to get that file again and put it into your dat_raw folder. Then change the incorrect statements.
Your other DATA steps also have problems (see the NOTEs about going to new lines) that need fixing.
Start from the beginning again. Seriously.
Restart SAS, make sure your files are downloaded again and start from scratch doing one step at a time.
@Curious4 wrote:
Okay, The dataset exists but the data doesn't print out as expected so exports don't work
data stress2;
file '/folders/myfolders/DATASETS/DAT/dat_raw/stress2.txt';
put name 1-20 resthr 22-24 maxhr 26-28 rechr 30-32 timemin 34-36 timesec 38-40
tolerance 42;
proc print; run;
This program say:
1) Start a data step to CREATE a dataset named STRESS2.
2) Open file ....stress2.txt for output.
3) write 7 variables into each line in fixed locations.
But what is does not do is every access any data that it could use to write to that dataset.
Did you mean to use a INFILE and INPUT statements instead ?
That would mean to create STRESS2 dataset from an existing file named .../stress2.txt .
But you will have to first find a new copy of that text file since if you ran the code you posed you have erased the existing text file and replaced it with an empty file.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.