I am looking to create vital signs dataset for practice. I have the following data. How can I convert this into data set
data vital;
infile datalines;
input usubjid$ param$ status$ visit$ firstdtc seconddtc type$
SD-1001-101 diastolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 diastolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 systolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 systolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 temp pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 temp post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 height pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 height post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 weight Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 weight Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 diastolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 diastolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 systolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 systolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 temp pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 temp post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 height pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 height post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 diastolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 diastolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 systolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 systolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 temp pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 temp post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 height pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 height post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 weight Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 weight Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 diastolic pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 diastolic post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 systolic pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 systolic post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 height pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 height post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 weight Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 weight Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-102 systolic pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-102 systolic post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-102 temp pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-102 temp post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 systolic pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 systolic post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 temp pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 temp post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 height pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 height post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 weight Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 weight Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
;
run;
Since your data seems to be neatly aligned, try this:
data vital;
infile datalines truncover;
input
@1 usubjid :$11.
@13 param :$10.
@23 status :$4.
@29 visit :$7.
@37 _firstdt anydtdte11.
@49 _firsttm time8.
@59 _seconddt anydtdte11.
@71 _secondtm time8.
@81 type :$10.
;
format firstdtc seconddtc e8601dt19.;
firstdtc = dhms(_firstdt,0,0,_firsttm);
seconddtc = dhms(_seconddt,0,0,_secondtm);
drop _:;
datalines;
SD-1001-101 diastolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 diastolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 systolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 systolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 temp pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 temp post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 height pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 height post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 weight Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 weight Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 diastolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 diastolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 systolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 systolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 temp pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 temp post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 height pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 height post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 diastolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 diastolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 systolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 systolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 temp pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 temp post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 height pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 height post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 weight Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 weight Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 diastolic pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 diastolic post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 systolic pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 systolic post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 height pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 height post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 weight Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 weight Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-102 systolic pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-102 systolic post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-102 temp pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-102 temp post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 systolic pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 systolic post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 temp pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 temp post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 height pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 height post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 weight Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 weight Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
;
You just want to create a SAS data set from this, correct?
@SASuserlot wrote:
Yes, I am having trouble with column statement.
More than that. You are having problems with 1) informats 2) missing DATALINES statement and 3) a not-standard-for-SAS date time appearance, or at least I can't find a "standard" date time format with the month abbreviation as shown.
data vital; infile datalines; informat usubjid $11. param $10. status $5. visit $7. firstdtc seconddtc $20. type $10. ; input usubjid $11. param status visit firstdtc seconddtc type ; array din firstdtc seconddtc; array dtc{2}; do i= 1 to dim(din); d = input(substr(din[i],1,11),anydtdte11.); t = input(substr(din[i],13,8),time.); dtc[i] = dhms(d,0,0,t); end; format dtc1 dtc2 datetime20.; drop i d t ; datalines; SD-1001-101 diastolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first ;
If you use a simple $ informat then the length of the variable is truncated to 8 characters. So I used and informat to specify longer values. Second with the non-typical date time I have broken into the date and time portions to then create a datetime value with the DHMS function.
You find with SAS it is usually a much better idea to have a common variable meaning appear first and then number them as I did with dtc1 and dtc2. For one thing there are places where you can use lists of variables and if you have 20 similar variables it is much easier to use dt1 - dtc20 to reference all of them instead of having to type first... second... nineteenth... and so on.
Having the date and time information in a datetime variable is much more flexible than a character value as there are functions to manipulate such and a number of formats to display the values.
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.
Since your data seems to be neatly aligned, try this:
data vital;
infile datalines truncover;
input
@1 usubjid :$11.
@13 param :$10.
@23 status :$4.
@29 visit :$7.
@37 _firstdt anydtdte11.
@49 _firsttm time8.
@59 _seconddt anydtdte11.
@71 _secondtm time8.
@81 type :$10.
;
format firstdtc seconddtc e8601dt19.;
firstdtc = dhms(_firstdt,0,0,_firsttm);
seconddtc = dhms(_seconddt,0,0,_secondtm);
drop _:;
datalines;
SD-1001-101 diastolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 diastolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 systolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 systolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 temp pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 temp post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 height pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 height post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 weight Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 weight Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 diastolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 diastolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 systolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 systolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 temp pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 temp post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 height pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 height post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 diastolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 diastolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 systolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 systolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 temp pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 temp post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 height pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 height post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 weight Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 weight Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 diastolic pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 diastolic post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 systolic pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 systolic post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 height pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 height post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 weight Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 weight Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-102 systolic pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-102 systolic post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-102 temp pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-102 temp post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 systolic pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 systolic post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 temp pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 temp post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 height pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 height post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 weight Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 weight Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
;
Thank you so much
I have a question regarding this solution. Your code works for me , however, I see observations as "Visi" where the "status " variable has missing values. Is there any way I can avoid issues during this step instead of going to the next step!
Look at the source data and make sure it does not have embedded TABs, as those will skew the positions.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.